home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 242 / Issue 242 - April 2008 - DPCS0408DVD.ISO / Open Source / AutoHotKey / Source / AutoHotkey104705_source.exe / source / lib_pcre / pcre / pcre_exec.c < prev    next >
Encoding:
C/C++ Source or Header  |  2007-11-20  |  147.4 KB  |  4,950 lines

  1. /*************************************************
  2. *      Perl-Compatible Regular Expressions       *
  3. *************************************************/
  4.  
  5. /* PCRE is a library of functions to support regular expressions whose syntax
  6. and semantics are as close as possible to those of the Perl 5 language.
  7.  
  8.                        Written by Philip Hazel
  9.            Copyright (c) 1997-2007 University of Cambridge
  10.  
  11. -----------------------------------------------------------------------------
  12. Redistribution and use in source and binary forms, with or without
  13. modification, are permitted provided that the following conditions are met:
  14.  
  15.     * Redistributions of source code must retain the above copyright notice,
  16.       this list of conditions and the following disclaimer.
  17.  
  18.     * Redistributions in binary form must reproduce the above copyright
  19.       notice, this list of conditions and the following disclaimer in the
  20.       documentation and/or other materials provided with the distribution.
  21.  
  22.     * Neither the name of the University of Cambridge nor the names of its
  23.       contributors may be used to endorse or promote products derived from
  24.       this software without specific prior written permission.
  25.  
  26. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. POSSIBILITY OF SUCH DAMAGE.
  37. -----------------------------------------------------------------------------
  38. */
  39.  
  40.  
  41. /* This module contains pcre_exec(), the externally visible function that does
  42. pattern matching using an NFA algorithm, trying to mimic Perl as closely as
  43. possible. There are also some static supporting functions. */
  44.  
  45. #ifdef HAVE_CONFIG_H
  46. #include "config.h"
  47. #endif
  48.  
  49. #define NLBLOCK md             /* Block containing newline information */
  50. #define PSSTART start_subject  /* Field containing processed string start */
  51. #define PSEND   end_subject    /* Field containing processed string end */
  52.  
  53. #include "pcre_internal.h"
  54.  
  55. /* Undefine some potentially clashing cpp symbols */
  56.  
  57. #undef min
  58. #undef max
  59.  
  60. /* Flag bits for the match() function */
  61.  
  62. #define match_condassert     0x01  /* Called to check a condition assertion */
  63. #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
  64.  
  65. /* Non-error returns from the match() function. Error returns are externally
  66. defined PCRE_ERROR_xxx codes, which are all negative. */
  67.  
  68. #define MATCH_MATCH        1
  69. #define MATCH_NOMATCH      0
  70.  
  71. /* Special internal returns from the match() function. Make them sufficiently
  72. negative to avoid the external error codes. */
  73.  
  74. #define MATCH_COMMIT       (-999)
  75. #define MATCH_PRUNE        (-998)
  76. #define MATCH_SKIP         (-997)
  77. #define MATCH_THEN         (-996)
  78.  
  79. /* Maximum number of ints of offset to save on the stack for recursive calls.
  80. If the offset vector is bigger, malloc is used. This should be a multiple of 3,
  81. because the offset vector is always a multiple of 3 long. */
  82.  
  83. #define REC_STACK_SAVE_MAX 30
  84.  
  85. /* Min and max values for the common repeats; for the maxima, 0 => infinity */
  86.  
  87. static const char rep_min[] = { 0, 0, 1, 1, 0, 0 };
  88. static const char rep_max[] = { 0, 0, 0, 0, 1, 1 };
  89.  
  90.  
  91.  
  92. #ifdef DEBUG
  93. /*************************************************
  94. *        Debugging function to print chars       *
  95. *************************************************/
  96.  
  97. /* Print a sequence of chars in printable format, stopping at the end of the
  98. subject if the requested.
  99.  
  100. Arguments:
  101.   p           points to characters
  102.   length      number to print
  103.   is_subject  TRUE if printing from within md->start_subject
  104.   md          pointer to matching data block, if is_subject is TRUE
  105.  
  106. Returns:     nothing
  107. */
  108.  
  109. static void
  110. pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
  111. {
  112. unsigned int c;
  113. if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
  114. while (length-- > 0)
  115.   if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
  116. }
  117. #endif
  118.  
  119.  
  120.  
  121. /*************************************************
  122. *          Match a back-reference                *
  123. *************************************************/
  124.  
  125. /* If a back reference hasn't been set, the length that is passed is greater
  126. than the number of characters left in the string, so the match fails.
  127.  
  128. Arguments:
  129.   offset      index into the offset vector
  130.   eptr        points into the subject
  131.   length      length to be matched
  132.   md          points to match data block
  133.   ims         the ims flags
  134.  
  135. Returns:      TRUE if matched
  136. */
  137.  
  138. static BOOL
  139. match_ref(int offset, register USPTR eptr, int length, match_data *md,
  140.   unsigned long int ims)
  141. {
  142. USPTR p = md->start_subject + md->offset_vector[offset];
  143.  
  144. #ifdef DEBUG
  145. if (eptr >= md->end_subject)
  146.   printf("matching subject <null>");
  147. else
  148.   {
  149.   printf("matching subject ");
  150.   pchars(eptr, length, TRUE, md);
  151.   }
  152. printf(" against backref ");
  153. pchars(p, length, FALSE, md);
  154. printf("\n");
  155. #endif
  156.  
  157. /* Always fail if not enough characters left */
  158.  
  159. if (length > md->end_subject - eptr) return FALSE;
  160.  
  161. /* Separate the caselesss case for speed */
  162.  
  163. if ((ims & PCRE_CASELESS) != 0)
  164.   {
  165.   while (length-- > 0)
  166.     if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;
  167.   }
  168. else
  169.   { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
  170.  
  171. return TRUE;
  172. }
  173.  
  174.  
  175.  
  176. /***************************************************************************
  177. ****************************************************************************
  178.                    RECURSION IN THE match() FUNCTION
  179.  
  180. The match() function is highly recursive, though not every recursive call
  181. increases the recursive depth. Nevertheless, some regular expressions can cause
  182. it to recurse to a great depth. I was writing for Unix, so I just let it call
  183. itself recursively. This uses the stack for saving everything that has to be
  184. saved for a recursive call. On Unix, the stack can be large, and this works
  185. fine.
  186.  
  187. It turns out that on some non-Unix-like systems there are problems with
  188. programs that use a lot of stack. (This despite the fact that every last chip
  189. has oodles of memory these days, and techniques for extending the stack have
  190. been known for decades.) So....
  191.  
  192. There is a fudge, triggered by defining NO_RECURSE, which avoids recursive
  193. calls by keeping local variables that need to be preserved in blocks of memory
  194. obtained from malloc() instead instead of on the stack. Macros are used to
  195. achieve this so that the actual code doesn't look very different to what it
  196. always used to.
  197.  
  198. The original heap-recursive code used longjmp(). However, it seems that this
  199. can be very slow on some operating systems. Following a suggestion from Stan
  200. Switzer, the use of longjmp() has been abolished, at the cost of having to
  201. provide a unique number for each call to RMATCH. There is no way of generating
  202. a sequence of numbers at compile time in C. I have given them names, to make
  203. them stand out more clearly.
  204.  
  205. Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
  206. FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
  207. tests. Furthermore, not using longjmp() means that local dynamic variables
  208. don't have indeterminate values; this has meant that the frame size can be
  209. reduced because the result can be "passed back" by straight setting of the
  210. variable instead of being passed in the frame.
  211. ****************************************************************************
  212. ***************************************************************************/
  213.  
  214. /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
  215. below must be updated in sync.  */
  216.  
  217. enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
  218.        RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
  219.        RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
  220.        RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
  221.        RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
  222.        RM51,  RM52, RM53, RM54 };
  223.  
  224. /* These versions of the macros use the stack, as normal. There are debugging
  225. versions and production versions. Note that the "rw" argument of RMATCH isn't
  226. actuall used in this definition. */
  227.  
  228. #ifndef NO_RECURSE
  229. #define REGISTER register
  230.  
  231. #ifdef DEBUG
  232. #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
  233.   { \
  234.   printf("match() called in line %d\n", __LINE__); \
  235.   rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
  236.   printf("to line %d\n", __LINE__); \
  237.   }
  238. #define RRETURN(ra) \
  239.   { \
  240.   printf("match() returned %d from line %d ", ra, __LINE__); \
  241.   return ra; \
  242.   }
  243. #else
  244. #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
  245.   rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
  246. #define RRETURN(ra) return ra
  247. #endif
  248.  
  249. #else
  250.  
  251.  
  252. /* These versions of the macros manage a private stack on the heap. Note that
  253. the "rd" argument of RMATCH isn't actually used in this definition. It's the md
  254. argument of match(), which never changes. */
  255.  
  256. #define REGISTER
  257.  
  258. #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
  259.   {\
  260.   heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
  261.   frame->Xwhere = rw; \
  262.   newframe->Xeptr = ra;\
  263.   newframe->Xecode = rb;\
  264.   newframe->Xmstart = mstart;\
  265.   newframe->Xoffset_top = rc;\
  266.   newframe->Xims = re;\
  267.   newframe->Xeptrb = rf;\
  268.   newframe->Xflags = rg;\
  269.   newframe->Xrdepth = frame->Xrdepth + 1;\
  270.   newframe->Xprevframe = frame;\
  271.   frame = newframe;\
  272.   DPRINTF(("restarting from line %d\n", __LINE__));\
  273.   goto HEAP_RECURSE;\
  274.   L_##rw:\
  275.   DPRINTF(("jumped back to line %d\n", __LINE__));\
  276.   }
  277.  
  278. #define RRETURN(ra)\
  279.   {\
  280.   heapframe *newframe = frame;\
  281.   frame = newframe->Xprevframe;\
  282.   (pcre_stack_free)(newframe);\
  283.   if (frame != NULL)\
  284.     {\
  285.     rrc = ra;\
  286.     goto HEAP_RETURN;\
  287.     }\
  288.   return ra;\
  289.   }
  290.  
  291.  
  292. /* Structure for remembering the local variables in a private frame */
  293.  
  294. typedef struct heapframe {
  295.   struct heapframe *Xprevframe;
  296.  
  297.   /* Function arguments that may change */
  298.  
  299.   const uschar *Xeptr;
  300.   const uschar *Xecode;
  301.   const uschar *Xmstart;
  302.   int Xoffset_top;
  303.   long int Xims;
  304.   eptrblock *Xeptrb;
  305.   int Xflags;
  306.   unsigned int Xrdepth;
  307.  
  308.   /* Function local variables */
  309.  
  310.   const uschar *Xcallpat;
  311.   const uschar *Xcharptr;
  312.   const uschar *Xdata;
  313.   const uschar *Xnext;
  314.   const uschar *Xpp;
  315.   const uschar *Xprev;
  316.   const uschar *Xsaved_eptr;
  317.  
  318.   recursion_info Xnew_recursive;
  319.  
  320.   BOOL Xcur_is_word;
  321.   BOOL Xcondition;
  322.   BOOL Xprev_is_word;
  323.  
  324.   unsigned long int Xoriginal_ims;
  325.  
  326. #ifdef SUPPORT_UCP
  327.   int Xprop_type;
  328.   int Xprop_value;
  329.   int Xprop_fail_result;
  330.   int Xprop_category;
  331.   int Xprop_chartype;
  332.   int Xprop_script;
  333.   int Xoclength;
  334.   uschar Xocchars[8];
  335. #endif
  336.  
  337.   int Xctype;
  338.   unsigned int Xfc;
  339.   int Xfi;
  340.   int Xlength;
  341.   int Xmax;
  342.   int Xmin;
  343.   int Xnumber;
  344.   int Xoffset;
  345.   int Xop;
  346.   int Xsave_capture_last;
  347.   int Xsave_offset1, Xsave_offset2, Xsave_offset3;
  348.   int Xstacksave[REC_STACK_SAVE_MAX];
  349.  
  350.   eptrblock Xnewptrb;
  351.  
  352.   /* Where to jump back to */
  353.  
  354.   int Xwhere;
  355.  
  356. } heapframe;
  357.  
  358. #endif
  359.  
  360.  
  361. /***************************************************************************
  362. ***************************************************************************/
  363.  
  364.  
  365.  
  366. /*************************************************
  367. *         Match from current position            *
  368. *************************************************/
  369.  
  370. /* This function is called recursively in many circumstances. Whenever it
  371. returns a negative (error) response, the outer incarnation must also return the
  372. same response.
  373.  
  374. Performance note: It might be tempting to extract commonly used fields from the
  375. md structure (e.g. utf8, end_subject) into individual variables to improve
  376. performance. Tests using gcc on a SPARC disproved this; in the first case, it
  377. made performance worse.
  378.  
  379. Arguments:
  380.    eptr        pointer to current character in subject
  381.    ecode       pointer to current position in compiled code
  382.    mstart      pointer to the current match start position (can be modified
  383.                  by encountering \K)
  384.    offset_top  current top pointer
  385.    md          pointer to "static" info for the match
  386.    ims         current /i, /m, and /s options
  387.    eptrb       pointer to chain of blocks containing eptr at start of
  388.                  brackets - for testing for empty matches
  389.    flags       can contain
  390.                  match_condassert - this is an assertion condition
  391.                  match_cbegroup - this is the start of an unlimited repeat
  392.                    group that can match an empty string
  393.    rdepth      the recursion depth
  394.  
  395. Returns:       MATCH_MATCH if matched            )  these values are >= 0
  396.                MATCH_NOMATCH if failed to match  )
  397.                a negative PCRE_ERROR_xxx value if aborted by an error condition
  398.                  (e.g. stopped by repeated call or recursion limit)
  399. */
  400.  
  401. static int
  402. match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,
  403.   int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
  404.   int flags, unsigned int rdepth)
  405. {
  406. /* These variables do not need to be preserved over recursion in this function,
  407. so they can be ordinary variables in all cases. Mark some of them with
  408. "register" because they are used a lot in loops. */
  409.  
  410. register int  rrc;         /* Returns from recursive calls */
  411. register int  i;           /* Used for loops not involving calls to RMATCH() */
  412. register unsigned int c;   /* Character values not kept over RMATCH() calls */
  413. #ifdef SUPPORT_UTF8 /* AutoHotkey: This helps detected unintended usages of utf8. */
  414.     register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
  415. #endif /* AutoHotkey. */
  416.  
  417. BOOL minimize, possessive; /* Quantifier options */
  418.  
  419. /* When recursion is not being used, all "local" variables that have to be
  420. preserved over calls to RMATCH() are part of a "frame" which is obtained from
  421. heap storage. Set up the top-level frame here; others are obtained from the
  422. heap whenever RMATCH() does a "recursion". See the macro definitions above. */
  423.  
  424. #ifdef NO_RECURSE
  425. heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));
  426. frame->Xprevframe = NULL;            /* Marks the top level */
  427.  
  428. /* Copy in the original argument variables */
  429.  
  430. frame->Xeptr = eptr;
  431. frame->Xecode = ecode;
  432. frame->Xmstart = mstart;
  433. frame->Xoffset_top = offset_top;
  434. frame->Xims = ims;
  435. frame->Xeptrb = eptrb;
  436. frame->Xflags = flags;
  437. frame->Xrdepth = rdepth;
  438.  
  439. /* This is where control jumps back to to effect "recursion" */
  440.  
  441. HEAP_RECURSE:
  442.  
  443. /* Macros make the argument variables come from the current frame */
  444.  
  445. #define eptr               frame->Xeptr
  446. #define ecode              frame->Xecode
  447. #define mstart             frame->Xmstart
  448. #define offset_top         frame->Xoffset_top
  449. #define ims                frame->Xims
  450. #define eptrb              frame->Xeptrb
  451. #define flags              frame->Xflags
  452. #define rdepth             frame->Xrdepth
  453.  
  454. /* Ditto for the local variables */
  455.  
  456. #ifdef SUPPORT_UTF8
  457. #define charptr            frame->Xcharptr
  458. #endif
  459. #define callpat            frame->Xcallpat
  460. #define data               frame->Xdata
  461. #define next               frame->Xnext
  462. #define pp                 frame->Xpp
  463. #define prev               frame->Xprev
  464. #define saved_eptr         frame->Xsaved_eptr
  465.  
  466. #define new_recursive      frame->Xnew_recursive
  467.  
  468. #define cur_is_word        frame->Xcur_is_word
  469. #define condition          frame->Xcondition
  470. #define prev_is_word       frame->Xprev_is_word
  471.  
  472. #define original_ims       frame->Xoriginal_ims
  473.  
  474. #ifdef SUPPORT_UCP
  475. #define prop_type          frame->Xprop_type
  476. #define prop_value         frame->Xprop_value
  477. #define prop_fail_result   frame->Xprop_fail_result
  478. #define prop_category      frame->Xprop_category
  479. #define prop_chartype      frame->Xprop_chartype
  480. #define prop_script        frame->Xprop_script
  481. #define oclength           frame->Xoclength
  482. #define occhars            frame->Xocchars
  483. #endif
  484.  
  485. #define ctype              frame->Xctype
  486. #define fc                 frame->Xfc
  487. #define fi                 frame->Xfi
  488. #define length             frame->Xlength
  489. #define max                frame->Xmax
  490. #define min                frame->Xmin
  491. #define number             frame->Xnumber
  492. #define offset             frame->Xoffset
  493. #define op                 frame->Xop
  494. #define save_capture_last  frame->Xsave_capture_last
  495. #define save_offset1       frame->Xsave_offset1
  496. #define save_offset2       frame->Xsave_offset2
  497. #define save_offset3       frame->Xsave_offset3
  498. #define stacksave          frame->Xstacksave
  499.  
  500. #define newptrb            frame->Xnewptrb
  501.  
  502. /* When recursion is being used, local variables are allocated on the stack and
  503. get preserved during recursion in the normal way. In this environment, fi and
  504. i, and fc and c, can be the same variables. */
  505.  
  506. #else         /* NO_RECURSE not defined */
  507. #define fi i
  508. #define fc c
  509.  
  510.  
  511. #ifdef SUPPORT_UTF8                /* Many of these variables are used only  */
  512. const uschar *charptr;             /* in small blocks of the code. My normal */
  513. #endif                             /* style of coding would have declared    */
  514. const uschar *callpat;             /* them within each of those blocks.      */
  515. const uschar *data;                /* However, in order to accommodate the   */
  516. const uschar *next;                /* version of this code that uses an      */
  517. USPTR         pp;                  /* external "stack" implemented on the    */
  518. const uschar *prev;                /* heap, it is easier to declare them all */
  519. USPTR         saved_eptr;          /* here, so the declarations can be cut   */
  520.                                    /* out in a block. The only declarations  */
  521. recursion_info new_recursive;      /* within blocks below are for variables  */
  522.                                    /* that do not have to be preserved over  */
  523. BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
  524. BOOL condition;
  525. BOOL prev_is_word;
  526.  
  527. unsigned long int original_ims;
  528.  
  529. #ifdef SUPPORT_UCP
  530. int prop_type;
  531. int prop_value;
  532. int prop_fail_result;
  533. int prop_category;
  534. int prop_chartype;
  535. int prop_script;
  536. int oclength;
  537. uschar occhars[8];
  538. #endif
  539.  
  540. int ctype;
  541. int length;
  542. int max;
  543. int min;
  544. int number;
  545. int offset;
  546. int op;
  547. int save_capture_last;
  548. int save_offset1, save_offset2, save_offset3;
  549. int stacksave[REC_STACK_SAVE_MAX];
  550.  
  551. eptrblock newptrb;
  552. #endif     /* NO_RECURSE */
  553.  
  554. /* These statements are here to stop the compiler complaining about unitialized
  555. variables. */
  556.  
  557. #ifdef SUPPORT_UCP
  558. prop_value = 0;
  559. prop_fail_result = 0;
  560. #endif
  561.  
  562.  
  563. /* This label is used for tail recursion, which is used in a few cases even
  564. when NO_RECURSE is not defined, in order to reduce the amount of stack that is
  565. used. Thanks to Ian Taylor for noticing this possibility and sending the
  566. original patch. */
  567.  
  568. TAIL_RECURSE:
  569.  
  570. /* OK, now we can get on with the real code of the function. Recursive calls
  571. are specified by the macro RMATCH and RRETURN is used to return. When
  572. NO_RECURSE is *not* defined, these just turn into a recursive call to match()
  573. and a "return", respectively (possibly with some debugging if DEBUG is
  574. defined). However, RMATCH isn't like a function call because it's quite a
  575. complicated macro. It has to be used in one particular way. This shouldn't,
  576. however, impact performance when true recursion is being used. */
  577.  
  578. #ifdef SUPPORT_UTF8
  579. utf8 = md->utf8;       /* Local copy of the flag */
  580. /* AutoHotkey: Commented out to help detect unintended usages of utf8:
  581. #else
  582. utf8 = FALSE; */
  583. #endif
  584.  
  585. /* First check that we haven't called match() too many times, or that we
  586. haven't exceeded the recursive call limit. */
  587.  
  588. if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);
  589. if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
  590.  
  591. original_ims = ims;    /* Save for resetting on ')' */
  592.  
  593. /* At the start of a group with an unlimited repeat that may match an empty
  594. string, the match_cbegroup flag is set. When this is the case, add the current
  595. subject pointer to the chain of such remembered pointers, to be checked when we
  596. hit the closing ket, in order to break infinite loops that match no characters.
  597. When match() is called in other circumstances, don't add to the chain. The
  598. match_cbegroup flag must NOT be used with tail recursion, because the memory
  599. block that is used is on the stack, so a new one may be required for each
  600. match(). */
  601.  
  602. if ((flags & match_cbegroup) != 0)
  603.   {
  604.   newptrb.epb_saved_eptr = eptr;
  605.   newptrb.epb_prev = eptrb;
  606.   eptrb = &newptrb;
  607.   }
  608.  
  609. /* Now start processing the opcodes. */
  610.  
  611. for (;;)
  612.   {
  613.   minimize = possessive = FALSE;
  614.   op = *ecode;
  615.  
  616.   /* For partial matching, remember if we ever hit the end of the subject after
  617.   matching at least one subject character. */
  618.  
  619.   if (md->partial &&
  620.       eptr >= md->end_subject &&
  621.       eptr > mstart)
  622.     md->hitend = TRUE;
  623.  
  624.   switch(op)
  625.     {
  626.     case OP_FAIL:
  627.     RRETURN(MATCH_NOMATCH);
  628.  
  629.     case OP_PRUNE:
  630.     RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  631.       ims, eptrb, flags, RM51);
  632.     if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  633.     RRETURN(MATCH_PRUNE);
  634.  
  635.     case OP_COMMIT:
  636.     RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  637.       ims, eptrb, flags, RM52);
  638.     if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  639.     RRETURN(MATCH_COMMIT);
  640.  
  641.     case OP_SKIP:
  642.     RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  643.       ims, eptrb, flags, RM53);
  644.     if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  645.     md->start_match_ptr = eptr;   /* Pass back current position */
  646.     RRETURN(MATCH_SKIP);
  647.  
  648.     case OP_THEN:
  649.     RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  650.       ims, eptrb, flags, RM54);
  651.     if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  652.     RRETURN(MATCH_THEN);
  653.  
  654.     /* Handle a capturing bracket. If there is space in the offset vector, save
  655.     the current subject position in the working slot at the top of the vector.
  656.     We mustn't change the current values of the data slot, because they may be
  657.     set from a previous iteration of this group, and be referred to by a
  658.     reference inside the group.
  659.  
  660.     If the bracket fails to match, we need to restore this value and also the
  661.     values of the final offsets, in case they were set by a previous iteration
  662.     of the same bracket.
  663.  
  664.     If there isn't enough space in the offset vector, treat this as if it were
  665.     a non-capturing bracket. Don't worry about setting the flag for the error
  666.     case here; that is handled in the code for KET. */
  667.  
  668.     case OP_CBRA:
  669.     case OP_SCBRA:
  670.     number = GET2(ecode, 1+LINK_SIZE);
  671.     offset = number << 1;
  672.  
  673. #ifdef DEBUG
  674.     printf("start bracket %d\n", number);
  675.     printf("subject=");
  676.     pchars(eptr, 16, TRUE, md);
  677.     printf("\n");
  678. #endif
  679.  
  680.     if (offset < md->offset_max)
  681.       {
  682.       save_offset1 = md->offset_vector[offset];
  683.       save_offset2 = md->offset_vector[offset+1];
  684.       save_offset3 = md->offset_vector[md->offset_end - number];
  685.       save_capture_last = md->capture_last;
  686.  
  687.       DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
  688.       md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
  689.  
  690.       flags = (op == OP_SCBRA)? match_cbegroup : 0;
  691.       do
  692.         {
  693.         RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  694.           ims, eptrb, flags, RM1);
  695.         if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  696.         md->capture_last = save_capture_last;
  697.         ecode += GET(ecode, 1);
  698.         }
  699.       while (*ecode == OP_ALT);
  700.  
  701.       DPRINTF(("bracket %d failed\n", number));
  702.  
  703.       md->offset_vector[offset] = save_offset1;
  704.       md->offset_vector[offset+1] = save_offset2;
  705.       md->offset_vector[md->offset_end - number] = save_offset3;
  706.  
  707.       RRETURN(MATCH_NOMATCH);
  708.       }
  709.  
  710.     /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
  711.     as a non-capturing bracket. */
  712.  
  713.     /* VVVVVVVVVVVVVVVVVVVVVVVVV */
  714.     /* VVVVVVVVVVVVVVVVVVVVVVVVV */
  715.  
  716.     DPRINTF(("insufficient capture room: treat as non-capturing\n"));
  717.  
  718.     /* VVVVVVVVVVVVVVVVVVVVVVVVV */
  719.     /* VVVVVVVVVVVVVVVVVVVVVVVVV */
  720.  
  721.     /* Non-capturing bracket. Loop for all the alternatives. When we get to the
  722.     final alternative within the brackets, we would return the result of a
  723.     recursive call to match() whatever happened. We can reduce stack usage by
  724.     turning this into a tail recursion, except in the case when match_cbegroup
  725.     is set.*/
  726.  
  727.     case OP_BRA:
  728.     case OP_SBRA:
  729.     DPRINTF(("start non-capturing bracket\n"));
  730.     flags = (op >= OP_SBRA)? match_cbegroup : 0;
  731.     for (;;)
  732.       {
  733.       if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
  734.         {
  735.         if (flags == 0)    /* Not a possibly empty group */
  736.           {
  737.           ecode += _pcre_OP_lengths[*ecode];
  738.           DPRINTF(("bracket 0 tail recursion\n"));
  739.           goto TAIL_RECURSE;
  740.           }
  741.  
  742.         /* Possibly empty group; can't use tail recursion. */
  743.  
  744.         RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
  745.           eptrb, flags, RM48);
  746.         RRETURN(rrc);
  747.         }
  748.  
  749.       /* For non-final alternatives, continue the loop for a NOMATCH result;
  750.       otherwise return. */
  751.  
  752.       RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
  753.         eptrb, flags, RM2);
  754.       if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  755.       ecode += GET(ecode, 1);
  756.       }
  757.     /* Control never reaches here. */
  758.  
  759.     /* Conditional group: compilation checked that there are no more than
  760.     two branches. If the condition is false, skipping the first branch takes us
  761.     past the end if there is only one branch, but that's OK because that is
  762.     exactly what going to the ket would do. As there is only one branch to be
  763.     obeyed, we can use tail recursion to avoid using another stack frame. */
  764.  
  765.     case OP_COND:
  766.     case OP_SCOND:
  767.     if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */
  768.       {
  769.       offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
  770.       condition = md->recursive != NULL &&
  771.         (offset == RREF_ANY || offset == md->recursive->group_num);
  772.       ecode += condition? 3 : GET(ecode, 1);
  773.       }
  774.  
  775.     else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */
  776.       {
  777.       offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
  778.       condition = offset < offset_top && md->offset_vector[offset] >= 0;
  779.       ecode += condition? 3 : GET(ecode, 1);
  780.       }
  781.  
  782.     else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */
  783.       {
  784.       condition = FALSE;
  785.       ecode += GET(ecode, 1);
  786.       }
  787.  
  788.     /* The condition is an assertion. Call match() to evaluate it - setting
  789.     the final argument match_condassert causes it to stop at the end of an
  790.     assertion. */
  791.  
  792.     else
  793.       {
  794.       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
  795.           match_condassert, RM3);
  796.       if (rrc == MATCH_MATCH)
  797.         {
  798.         condition = TRUE;
  799.         ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
  800.         while (*ecode == OP_ALT) ecode += GET(ecode, 1);
  801.         }
  802.       else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
  803.         {
  804.         RRETURN(rrc);         /* Need braces because of following else */
  805.         }
  806.       else
  807.         {
  808.         condition = FALSE;
  809.         ecode += GET(ecode, 1);
  810.         }
  811.       }
  812.  
  813.     /* We are now at the branch that is to be obeyed. As there is only one,
  814.     we can use tail recursion to avoid using another stack frame, except when
  815.     match_cbegroup is required for an unlimited repeat of a possibly empty
  816.     group. If the second alternative doesn't exist, we can just plough on. */
  817.  
  818.     if (condition || *ecode == OP_ALT)
  819.       {
  820.       ecode += 1 + LINK_SIZE;
  821.       if (op == OP_SCOND)        /* Possibly empty group */
  822.         {
  823.         RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
  824.         RRETURN(rrc);
  825.         }
  826.       else                       /* Group must match something */
  827.         {
  828.         flags = 0;
  829.         goto TAIL_RECURSE;
  830.         }
  831.       }
  832.     else                         /* Condition false & no 2nd alternative */
  833.       {
  834.       ecode += 1 + LINK_SIZE;
  835.       }
  836.     break;
  837.  
  838.  
  839.     /* End of the pattern, either real or forced. If we are in a top-level
  840.     recursion, we should restore the offsets appropriately and continue from
  841.     after the call. */
  842.  
  843.     case OP_ACCEPT:
  844.     case OP_END:
  845.     if (md->recursive != NULL && md->recursive->group_num == 0)
  846.       {
  847.       recursion_info *rec = md->recursive;
  848.       DPRINTF(("End of pattern in a (?0) recursion\n"));
  849.       md->recursive = rec->prevrec;
  850.       memmove(md->offset_vector, rec->offset_save,
  851.         rec->saved_max * sizeof(int));
  852.       mstart = rec->save_start;
  853.       ims = original_ims;
  854.       ecode = rec->after_call;
  855.       break;
  856.       }
  857.  
  858.     /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
  859.     string - backtracking will then try other alternatives, if any. */
  860.  
  861.     if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
  862.     md->end_match_ptr = eptr;           /* Record where we ended */
  863.     md->end_offset_top = offset_top;    /* and how many extracts were taken */
  864.     md->start_match_ptr = mstart;       /* and the start (\K can modify) */
  865.     RRETURN(MATCH_MATCH);
  866.  
  867.     /* Change option settings */
  868.  
  869.     case OP_OPT:
  870.     ims = ecode[1];
  871.     ecode += 2;
  872.     DPRINTF(("ims set to %02lx\n", ims));
  873.     break;
  874.  
  875.     /* Assertion brackets. Check the alternative branches in turn - the
  876.     matching won't pass the KET for an assertion. If any one branch matches,
  877.     the assertion is true. Lookbehind assertions have an OP_REVERSE item at the
  878.     start of each branch to move the current point backwards, so the code at
  879.     this level is identical to the lookahead case. */
  880.  
  881.     case OP_ASSERT:
  882.     case OP_ASSERTBACK:
  883.     do
  884.       {
  885.       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
  886.         RM4);
  887.       if (rrc == MATCH_MATCH) break;
  888.       if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  889.       ecode += GET(ecode, 1);
  890.       }
  891.     while (*ecode == OP_ALT);
  892.     if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);
  893.  
  894.     /* If checking an assertion for a condition, return MATCH_MATCH. */
  895.  
  896.     if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);
  897.  
  898.     /* Continue from after the assertion, updating the offsets high water
  899.     mark, since extracts may have been taken during the assertion. */
  900.  
  901.     do ecode += GET(ecode,1); while (*ecode == OP_ALT);
  902.     ecode += 1 + LINK_SIZE;
  903.     offset_top = md->end_offset_top;
  904.     continue;
  905.  
  906.     /* Negative assertion: all branches must fail to match */
  907.  
  908.     case OP_ASSERT_NOT:
  909.     case OP_ASSERTBACK_NOT:
  910.     do
  911.       {
  912.       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
  913.         RM5);
  914.       if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
  915.       if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  916.       ecode += GET(ecode,1);
  917.       }
  918.     while (*ecode == OP_ALT);
  919.  
  920.     if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);
  921.  
  922.     ecode += 1 + LINK_SIZE;
  923.     continue;
  924.  
  925.     /* Move the subject pointer back. This occurs only at the start of
  926.     each branch of a lookbehind assertion. If we are too close to the start to
  927.     move back, this match function fails. When working with UTF-8 we move
  928.     back a number of characters, not bytes. */
  929.  
  930.     case OP_REVERSE:
  931. #ifdef SUPPORT_UTF8
  932.     if (utf8)
  933.       {
  934.       i = GET(ecode, 1);
  935.       while (i-- > 0)
  936.         {
  937.         eptr--;
  938.         if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
  939.         BACKCHAR(eptr);
  940.         }
  941.       }
  942.     else
  943. #endif
  944.  
  945.     /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
  946.  
  947.       {
  948.       eptr -= GET(ecode, 1);
  949.       if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
  950.       }
  951.  
  952.     /* Skip to next op code */
  953.  
  954.     ecode += 1 + LINK_SIZE;
  955.     break;
  956.  
  957.     /* The callout item calls an external function, if one is provided, passing
  958.     details of the match so far. This is mainly for debugging, though the
  959.     function is able to force a failure. */
  960.  
  961.     case OP_CALLOUT:
  962. #ifdef SUPPORT_CALLOUT  /* AutoHotkey: Omit the callout feature from the code until it's needed. */
  963.     if (pcre_callout != NULL)
  964.       {
  965.       pcre_callout_block cb;
  966.       cb.version          = 1;   /* Version 1 of the callout block */
  967.       cb.callout_number   = ecode[1];
  968.       cb.offset_vector    = md->offset_vector;
  969.       cb.subject          = (PCRE_SPTR)md->start_subject;
  970.       cb.subject_length   = md->end_subject - md->start_subject;
  971.       cb.start_match      = mstart - md->start_subject;
  972.       cb.current_position = eptr - md->start_subject;
  973.       cb.pattern_position = GET(ecode, 2);
  974.       cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
  975.       cb.capture_top      = offset_top/2;
  976.       cb.capture_last     = md->capture_last;
  977.       cb.callout_data     = md->callout_data;
  978.       if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
  979.       if (rrc < 0) RRETURN(rrc);
  980.       }
  981. #endif /* AutoHotkey */
  982.     ecode += 2 + 2*LINK_SIZE;
  983.     break;
  984.  
  985.     /* Recursion either matches the current regex, or some subexpression. The
  986.     offset data is the offset to the starting bracket from the start of the
  987.     whole pattern. (This is so that it works from duplicated subpatterns.)
  988.  
  989.     If there are any capturing brackets started but not finished, we have to
  990.     save their starting points and reinstate them after the recursion. However,
  991.     we don't know how many such there are (offset_top records the completed
  992.     total) so we just have to save all the potential data. There may be up to
  993.     65535 such values, which is too large to put on the stack, but using malloc
  994.     for small numbers seems expensive. As a compromise, the stack is used when
  995.     there are no more than REC_STACK_SAVE_MAX values to store; otherwise malloc
  996.     is used. A problem is what to do if the malloc fails ... there is no way of
  997.     returning to the top level with an error. Save the top REC_STACK_SAVE_MAX
  998.     values on the stack, and accept that the rest may be wrong.
  999.  
  1000.     There are also other values that have to be saved. We use a chained
  1001.     sequence of blocks that actually live on the stack. Thanks to Robin Houston
  1002.     for the original version of this logic. */
  1003.  
  1004.     case OP_RECURSE:
  1005.       {
  1006.       callpat = md->start_code + GET(ecode, 1);
  1007.       new_recursive.group_num = (callpat == md->start_code)? 0 :
  1008.         GET2(callpat, 1 + LINK_SIZE);
  1009.  
  1010.       /* Add to "recursing stack" */
  1011.  
  1012.       new_recursive.prevrec = md->recursive;
  1013.       md->recursive = &new_recursive;
  1014.  
  1015.       /* Find where to continue from afterwards */
  1016.  
  1017.       ecode += 1 + LINK_SIZE;
  1018.       new_recursive.after_call = ecode;
  1019.  
  1020.       /* Now save the offset data. */
  1021.  
  1022.       new_recursive.saved_max = md->offset_end;
  1023.       if (new_recursive.saved_max <= REC_STACK_SAVE_MAX)
  1024.         new_recursive.offset_save = stacksave;
  1025.       else
  1026.         {
  1027.         new_recursive.offset_save =
  1028.           (int *)(pcre_malloc)(new_recursive.saved_max * sizeof(int));
  1029.         if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
  1030.         }
  1031.  
  1032.       memcpy(new_recursive.offset_save, md->offset_vector,
  1033.             new_recursive.saved_max * sizeof(int));
  1034.       new_recursive.save_start = mstart;
  1035.       mstart = eptr;
  1036.  
  1037.       /* OK, now we can do the recursion. For each top-level alternative we
  1038.       restore the offset and recursion data. */
  1039.  
  1040.       DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
  1041.       flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
  1042.       do
  1043.         {
  1044.         RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
  1045.           md, ims, eptrb, flags, RM6);
  1046.         if (rrc == MATCH_MATCH)
  1047.           {
  1048.           DPRINTF(("Recursion matched\n"));
  1049.           md->recursive = new_recursive.prevrec;
  1050.           if (new_recursive.offset_save != stacksave)
  1051.             (pcre_free)(new_recursive.offset_save);
  1052.           RRETURN(MATCH_MATCH);
  1053.           }
  1054.         else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
  1055.           {
  1056.           DPRINTF(("Recursion gave error %d\n", rrc));
  1057.           RRETURN(rrc);
  1058.           }
  1059.  
  1060.         md->recursive = &new_recursive;
  1061.         memcpy(md->offset_vector, new_recursive.offset_save,
  1062.             new_recursive.saved_max * sizeof(int));
  1063.         callpat += GET(callpat, 1);
  1064.         }
  1065.       while (*callpat == OP_ALT);
  1066.  
  1067.       DPRINTF(("Recursion didn't match\n"));
  1068.       md->recursive = new_recursive.prevrec;
  1069.       if (new_recursive.offset_save != stacksave)
  1070.         (pcre_free)(new_recursive.offset_save);
  1071.       RRETURN(MATCH_NOMATCH);
  1072.       }
  1073.     /* Control never reaches here */
  1074.  
  1075.     /* "Once" brackets are like assertion brackets except that after a match,
  1076.     the point in the subject string is not moved back. Thus there can never be
  1077.     a move back into the brackets. Friedl calls these "atomic" subpatterns.
  1078.     Check the alternative branches in turn - the matching won't pass the KET
  1079.     for this kind of subpattern. If any one branch matches, we carry on as at
  1080.     the end of a normal bracket, leaving the subject pointer. */
  1081.  
  1082.     case OP_ONCE:
  1083.     prev = ecode;
  1084.     saved_eptr = eptr;
  1085.  
  1086.     do
  1087.       {
  1088.       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
  1089.       if (rrc == MATCH_MATCH) break;
  1090.       if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  1091.       ecode += GET(ecode,1);
  1092.       }
  1093.     while (*ecode == OP_ALT);
  1094.  
  1095.     /* If hit the end of the group (which could be repeated), fail */
  1096.  
  1097.     if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
  1098.  
  1099.     /* Continue as from after the assertion, updating the offsets high water
  1100.     mark, since extracts may have been taken. */
  1101.  
  1102.     do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
  1103.  
  1104.     offset_top = md->end_offset_top;
  1105.     eptr = md->end_match_ptr;
  1106.  
  1107.     /* For a non-repeating ket, just continue at this level. This also
  1108.     happens for a repeating ket if no characters were matched in the group.
  1109.     This is the forcible breaking of infinite loops as implemented in Perl
  1110.     5.005. If there is an options reset, it will get obeyed in the normal
  1111.     course of events. */
  1112.  
  1113.     if (*ecode == OP_KET || eptr == saved_eptr)
  1114.       {
  1115.       ecode += 1+LINK_SIZE;
  1116.       break;
  1117.       }
  1118.  
  1119.     /* The repeating kets try the rest of the pattern or restart from the
  1120.     preceding bracket, in the appropriate order. The second "call" of match()
  1121.     uses tail recursion, to avoid using another stack frame. We need to reset
  1122.     any options that changed within the bracket before re-running it, so
  1123.     check the next opcode. */
  1124.  
  1125.     if (ecode[1+LINK_SIZE] == OP_OPT)
  1126.       {
  1127.       ims = (ims & ~PCRE_IMS) | ecode[4];
  1128.       DPRINTF(("ims set to %02lx at group repeat\n", ims));
  1129.       }
  1130.  
  1131.     if (*ecode == OP_KETRMIN)
  1132.       {
  1133.       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
  1134.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1135.       ecode = prev;
  1136.       flags = 0;
  1137.       goto TAIL_RECURSE;
  1138.       }
  1139.     else  /* OP_KETRMAX */
  1140.       {
  1141.       RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
  1142.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1143.       ecode += 1 + LINK_SIZE;
  1144.       flags = 0;
  1145.       goto TAIL_RECURSE;
  1146.       }
  1147.     /* Control never gets here */
  1148.  
  1149.     /* An alternation is the end of a branch; scan along to find the end of the
  1150.     bracketed group and go to there. */
  1151.  
  1152.     case OP_ALT:
  1153.     do ecode += GET(ecode,1); while (*ecode == OP_ALT);
  1154.     break;
  1155.  
  1156.     /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating
  1157.     that it may occur zero times. It may repeat infinitely, or not at all -
  1158.     i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper
  1159.     repeat limits are compiled as a number of copies, with the optional ones
  1160.     preceded by BRAZERO or BRAMINZERO. */
  1161.  
  1162.     case OP_BRAZERO:
  1163.       {
  1164.       next = ecode+1;
  1165.       RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
  1166.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1167.       do next += GET(next,1); while (*next == OP_ALT);
  1168.       ecode = next + 1 + LINK_SIZE;
  1169.       }
  1170.     break;
  1171.  
  1172.     case OP_BRAMINZERO:
  1173.       {
  1174.       next = ecode+1;
  1175.       do next += GET(next, 1); while (*next == OP_ALT);
  1176.       RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
  1177.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1178.       ecode++;
  1179.       }
  1180.     break;
  1181.  
  1182.     /* End of a group, repeated or non-repeating. */
  1183.  
  1184.     case OP_KET:
  1185.     case OP_KETRMIN:
  1186.     case OP_KETRMAX:
  1187.     prev = ecode - GET(ecode, 1);
  1188.  
  1189.     /* If this was a group that remembered the subject start, in order to break
  1190.     infinite repeats of empty string matches, retrieve the subject start from
  1191.     the chain. Otherwise, set it NULL. */
  1192.  
  1193.     if (*prev >= OP_SBRA)
  1194.       {
  1195.       saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
  1196.       eptrb = eptrb->epb_prev;              /* Backup to previous group */
  1197.       }
  1198.     else saved_eptr = NULL;
  1199.  
  1200.     /* If we are at the end of an assertion group, stop matching and return
  1201.     MATCH_MATCH, but record the current high water mark for use by positive
  1202.     assertions. Do this also for the "once" (atomic) groups. */
  1203.  
  1204.     if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
  1205.         *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
  1206.         *prev == OP_ONCE)
  1207.       {
  1208.       md->end_match_ptr = eptr;      /* For ONCE */
  1209.       md->end_offset_top = offset_top;
  1210.       RRETURN(MATCH_MATCH);
  1211.       }
  1212.  
  1213.     /* For capturing groups we have to check the group number back at the start
  1214.     and if necessary complete handling an extraction by setting the offsets and
  1215.     bumping the high water mark. Note that whole-pattern recursion is coded as
  1216.     a recurse into group 0, so it won't be picked up here. Instead, we catch it
  1217.     when the OP_END is reached. Other recursion is handled here. */
  1218.  
  1219.     if (*prev == OP_CBRA || *prev == OP_SCBRA)
  1220.       {
  1221.       number = GET2(prev, 1+LINK_SIZE);
  1222.       offset = number << 1;
  1223.  
  1224. #ifdef DEBUG
  1225.       printf("end bracket %d", number);
  1226.       printf("\n");
  1227. #endif
  1228.  
  1229.       md->capture_last = number;
  1230.       if (offset >= md->offset_max) md->offset_overflow = TRUE; else
  1231.         {
  1232.         md->offset_vector[offset] =
  1233.           md->offset_vector[md->offset_end - number];
  1234.         md->offset_vector[offset+1] = eptr - md->start_subject;
  1235.         if (offset_top <= offset) offset_top = offset + 2;
  1236.         }
  1237.  
  1238.       /* Handle a recursively called group. Restore the offsets
  1239.       appropriately and continue from after the call. */
  1240.  
  1241.       if (md->recursive != NULL && md->recursive->group_num == number)
  1242.         {
  1243.         recursion_info *rec = md->recursive;
  1244.         DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
  1245.         md->recursive = rec->prevrec;
  1246.         mstart = rec->save_start;
  1247.         memcpy(md->offset_vector, rec->offset_save,
  1248.           rec->saved_max * sizeof(int));
  1249.         ecode = rec->after_call;
  1250.         ims = original_ims;
  1251.         break;
  1252.         }
  1253.       }
  1254.  
  1255.     /* For both capturing and non-capturing groups, reset the value of the ims
  1256.     flags, in case they got changed during the group. */
  1257.  
  1258.     ims = original_ims;
  1259.     DPRINTF(("ims reset to %02lx\n", ims));
  1260.  
  1261.     /* For a non-repeating ket, just continue at this level. This also
  1262.     happens for a repeating ket if no characters were matched in the group.
  1263.     This is the forcible breaking of infinite loops as implemented in Perl
  1264.     5.005. If there is an options reset, it will get obeyed in the normal
  1265.     course of events. */
  1266.  
  1267.     if (*ecode == OP_KET || eptr == saved_eptr)
  1268.       {
  1269.       ecode += 1 + LINK_SIZE;
  1270.       break;
  1271.       }
  1272.  
  1273.     /* The repeating kets try the rest of the pattern or restart from the
  1274.     preceding bracket, in the appropriate order. In the second case, we can use
  1275.     tail recursion to avoid using another stack frame, unless we have an
  1276.     unlimited repeat of a group that can match an empty string. */
  1277.  
  1278.     flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
  1279.  
  1280.     if (*ecode == OP_KETRMIN)
  1281.       {
  1282.       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
  1283.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1284.       if (flags != 0)    /* Could match an empty string */
  1285.         {
  1286.         RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
  1287.         RRETURN(rrc);
  1288.         }
  1289.       ecode = prev;
  1290.       goto TAIL_RECURSE;
  1291.       }
  1292.     else  /* OP_KETRMAX */
  1293.       {
  1294.       RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
  1295.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1296.       ecode += 1 + LINK_SIZE;
  1297.       flags = 0;
  1298.       goto TAIL_RECURSE;
  1299.       }
  1300.     /* Control never gets here */
  1301.  
  1302.     /* Start of subject unless notbol, or after internal newline if multiline */
  1303.  
  1304.     case OP_CIRC:
  1305.     if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
  1306.     if ((ims & PCRE_MULTILINE) != 0)
  1307.       {
  1308.       if (eptr != md->start_subject &&
  1309.           (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
  1310.         RRETURN(MATCH_NOMATCH);
  1311.       ecode++;
  1312.       break;
  1313.       }
  1314.     /* ... else fall through */
  1315.  
  1316.     /* Start of subject assertion */
  1317.  
  1318.     case OP_SOD:
  1319.     if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);
  1320.     ecode++;
  1321.     break;
  1322.  
  1323.     /* Start of match assertion */
  1324.  
  1325.     case OP_SOM:
  1326.     if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);
  1327.     ecode++;
  1328.     break;
  1329.  
  1330.     /* Reset the start of match point */
  1331.  
  1332.     case OP_SET_SOM:
  1333.     mstart = eptr;
  1334.     ecode++;
  1335.     break;
  1336.  
  1337.     /* Assert before internal newline if multiline, or before a terminating
  1338.     newline unless endonly is set, else end of subject unless noteol is set. */
  1339.  
  1340.     case OP_DOLL:
  1341.     if ((ims & PCRE_MULTILINE) != 0)
  1342.       {
  1343.       if (eptr < md->end_subject)
  1344.         { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
  1345.       else
  1346.         { if (md->noteol) RRETURN(MATCH_NOMATCH); }
  1347.       ecode++;
  1348.       break;
  1349.       }
  1350.     else
  1351.       {
  1352.       if (md->noteol) RRETURN(MATCH_NOMATCH);
  1353.       if (!md->endonly)
  1354.         {
  1355.         if (eptr != md->end_subject &&
  1356.             (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
  1357.           RRETURN(MATCH_NOMATCH);
  1358.         ecode++;
  1359.         break;
  1360.         }
  1361.       }
  1362.     /* ... else fall through for endonly */
  1363.  
  1364.     /* End of subject assertion (\z) */
  1365.  
  1366.     case OP_EOD:
  1367.     if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);
  1368.     ecode++;
  1369.     break;
  1370.  
  1371.     /* End of subject or ending \n assertion (\Z) */
  1372.  
  1373.     case OP_EODN:
  1374.     if (eptr != md->end_subject &&
  1375.         (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
  1376.       RRETURN(MATCH_NOMATCH);
  1377.     ecode++;
  1378.     break;
  1379.  
  1380.     /* Word boundary assertions */
  1381.  
  1382.     case OP_NOT_WORD_BOUNDARY:
  1383.     case OP_WORD_BOUNDARY:
  1384.       {
  1385.  
  1386.       /* Find out if the previous and current characters are "word" characters.
  1387.       It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
  1388.       be "non-word" characters. */
  1389.  
  1390. #ifdef SUPPORT_UTF8
  1391.       if (utf8)
  1392.         {
  1393.         if (eptr == md->start_subject) prev_is_word = FALSE; else
  1394.           {
  1395.           const uschar *lastptr = eptr - 1;
  1396.           while((*lastptr & 0xc0) == 0x80) lastptr--;
  1397.           GETCHAR(c, lastptr);
  1398.           prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
  1399.           }
  1400.         if (eptr >= md->end_subject) cur_is_word = FALSE; else
  1401.           {
  1402.           GETCHAR(c, eptr);
  1403.           cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
  1404.           }
  1405.         }
  1406.       else
  1407. #endif
  1408.  
  1409.       /* More streamlined when not in UTF-8 mode */
  1410.  
  1411.         {
  1412.         prev_is_word = (eptr != md->start_subject) &&
  1413.           ((md->ctypes[eptr[-1]] & ctype_word) != 0);
  1414.         cur_is_word = (eptr < md->end_subject) &&
  1415.           ((md->ctypes[*eptr] & ctype_word) != 0);
  1416.         }
  1417.  
  1418.       /* Now see if the situation is what we want */
  1419.  
  1420.       if ((*ecode++ == OP_WORD_BOUNDARY)?
  1421.            cur_is_word == prev_is_word : cur_is_word != prev_is_word)
  1422.         RRETURN(MATCH_NOMATCH);
  1423.       }
  1424.     break;
  1425.  
  1426.     /* Match a single character type; inline for speed */
  1427.  
  1428.     case OP_ANY:
  1429.     if ((ims & PCRE_DOTALL) == 0)
  1430.       {
  1431.       if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
  1432.       }
  1433.     if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1434. #ifdef SUPPORT_UTF8 /* AutoHotkey: Apparently this line was forgotten because all the other "if utf8" sections have it */
  1435.     if (utf8)
  1436.       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  1437. #endif /* AutoHotkey. */
  1438.     ecode++;
  1439.     break;
  1440.  
  1441.     /* Match a single byte, even in UTF-8 mode. This opcode really does match
  1442.     any byte, even newline, independent of the setting of PCRE_DOTALL. */
  1443.  
  1444.     case OP_ANYBYTE:
  1445.     if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1446.     ecode++;
  1447.     break;
  1448.  
  1449.     case OP_NOT_DIGIT:
  1450.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1451.     GETCHARINCTEST(c, eptr);
  1452.     if (
  1453. #ifdef SUPPORT_UTF8
  1454.        c < 256 &&
  1455. #endif
  1456.        (md->ctypes[c] & ctype_digit) != 0
  1457.        )
  1458.       RRETURN(MATCH_NOMATCH);
  1459.     ecode++;
  1460.     break;
  1461.  
  1462.     case OP_DIGIT:
  1463.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1464.     GETCHARINCTEST(c, eptr);
  1465.     if (
  1466. #ifdef SUPPORT_UTF8
  1467.        c >= 256 ||
  1468. #endif
  1469.        (md->ctypes[c] & ctype_digit) == 0
  1470.        )
  1471.       RRETURN(MATCH_NOMATCH);
  1472.     ecode++;
  1473.     break;
  1474.  
  1475.     case OP_NOT_WHITESPACE:
  1476.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1477.     GETCHARINCTEST(c, eptr);
  1478.     if (
  1479. #ifdef SUPPORT_UTF8
  1480.        c < 256 &&
  1481. #endif
  1482.        (md->ctypes[c] & ctype_space) != 0
  1483.        )
  1484.       RRETURN(MATCH_NOMATCH);
  1485.     ecode++;
  1486.     break;
  1487.  
  1488.     case OP_WHITESPACE:
  1489.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1490.     GETCHARINCTEST(c, eptr);
  1491.     if (
  1492. #ifdef SUPPORT_UTF8
  1493.        c >= 256 ||
  1494. #endif
  1495.        (md->ctypes[c] & ctype_space) == 0
  1496.        )
  1497.       RRETURN(MATCH_NOMATCH);
  1498.     ecode++;
  1499.     break;
  1500.  
  1501.     case OP_NOT_WORDCHAR:
  1502.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1503.     GETCHARINCTEST(c, eptr);
  1504.     if (
  1505. #ifdef SUPPORT_UTF8
  1506.        c < 256 &&
  1507. #endif
  1508.        (md->ctypes[c] & ctype_word) != 0
  1509.        )
  1510.       RRETURN(MATCH_NOMATCH);
  1511.     ecode++;
  1512.     break;
  1513.  
  1514.     case OP_WORDCHAR:
  1515.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1516.     GETCHARINCTEST(c, eptr);
  1517.     if (
  1518. #ifdef SUPPORT_UTF8
  1519.        c >= 256 ||
  1520. #endif
  1521.        (md->ctypes[c] & ctype_word) == 0
  1522.        )
  1523.       RRETURN(MATCH_NOMATCH);
  1524.     ecode++;
  1525.     break;
  1526.  
  1527.     case OP_ANYNL:
  1528.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1529.     GETCHARINCTEST(c, eptr);
  1530.     switch(c)
  1531.       {
  1532.       default: RRETURN(MATCH_NOMATCH);
  1533.       case 0x000d:
  1534.       if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  1535.       break;
  1536.  
  1537.       case 0x000a:
  1538.       break;
  1539.  
  1540.       case 0x000b:
  1541.       case 0x000c:
  1542.       case 0x0085:
  1543.       case 0x2028:
  1544.       case 0x2029:
  1545.       if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  1546.       break;
  1547.       }
  1548.     ecode++;
  1549.     break;
  1550.  
  1551.     case OP_NOT_HSPACE:
  1552.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1553.     GETCHARINCTEST(c, eptr);
  1554.     switch(c)
  1555.       {
  1556.       default: break;
  1557.       case 0x09:      /* HT */
  1558.       case 0x20:      /* SPACE */
  1559.       case 0xa0:      /* NBSP */
  1560.       case 0x1680:    /* OGHAM SPACE MARK */
  1561.       case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
  1562.       case 0x2000:    /* EN QUAD */
  1563.       case 0x2001:    /* EM QUAD */
  1564.       case 0x2002:    /* EN SPACE */
  1565.       case 0x2003:    /* EM SPACE */
  1566.       case 0x2004:    /* THREE-PER-EM SPACE */
  1567.       case 0x2005:    /* FOUR-PER-EM SPACE */
  1568.       case 0x2006:    /* SIX-PER-EM SPACE */
  1569.       case 0x2007:    /* FIGURE SPACE */
  1570.       case 0x2008:    /* PUNCTUATION SPACE */
  1571.       case 0x2009:    /* THIN SPACE */
  1572.       case 0x200A:    /* HAIR SPACE */
  1573.       case 0x202f:    /* NARROW NO-BREAK SPACE */
  1574.       case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
  1575.       case 0x3000:    /* IDEOGRAPHIC SPACE */
  1576.       RRETURN(MATCH_NOMATCH);
  1577.       }
  1578.     ecode++;
  1579.     break;
  1580.  
  1581.     case OP_HSPACE:
  1582.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1583.     GETCHARINCTEST(c, eptr);
  1584.     switch(c)
  1585.       {
  1586.       default: RRETURN(MATCH_NOMATCH);
  1587.       case 0x09:      /* HT */
  1588.       case 0x20:      /* SPACE */
  1589.       case 0xa0:      /* NBSP */
  1590.       case 0x1680:    /* OGHAM SPACE MARK */
  1591.       case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
  1592.       case 0x2000:    /* EN QUAD */
  1593.       case 0x2001:    /* EM QUAD */
  1594.       case 0x2002:    /* EN SPACE */
  1595.       case 0x2003:    /* EM SPACE */
  1596.       case 0x2004:    /* THREE-PER-EM SPACE */
  1597.       case 0x2005:    /* FOUR-PER-EM SPACE */
  1598.       case 0x2006:    /* SIX-PER-EM SPACE */
  1599.       case 0x2007:    /* FIGURE SPACE */
  1600.       case 0x2008:    /* PUNCTUATION SPACE */
  1601.       case 0x2009:    /* THIN SPACE */
  1602.       case 0x200A:    /* HAIR SPACE */
  1603.       case 0x202f:    /* NARROW NO-BREAK SPACE */
  1604.       case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
  1605.       case 0x3000:    /* IDEOGRAPHIC SPACE */
  1606.       break;
  1607.       }
  1608.     ecode++;
  1609.     break;
  1610.  
  1611.     case OP_NOT_VSPACE:
  1612.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1613.     GETCHARINCTEST(c, eptr);
  1614.     switch(c)
  1615.       {
  1616.       default: break;
  1617.       case 0x0a:      /* LF */
  1618.       case 0x0b:      /* VT */
  1619.       case 0x0c:      /* FF */
  1620.       case 0x0d:      /* CR */
  1621.       case 0x85:      /* NEL */
  1622.       case 0x2028:    /* LINE SEPARATOR */
  1623.       case 0x2029:    /* PARAGRAPH SEPARATOR */
  1624.       RRETURN(MATCH_NOMATCH);
  1625.       }
  1626.     ecode++;
  1627.     break;
  1628.  
  1629.     case OP_VSPACE:
  1630.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1631.     GETCHARINCTEST(c, eptr);
  1632.     switch(c)
  1633.       {
  1634.       default: RRETURN(MATCH_NOMATCH);
  1635.       case 0x0a:      /* LF */
  1636.       case 0x0b:      /* VT */
  1637.       case 0x0c:      /* FF */
  1638.       case 0x0d:      /* CR */
  1639.       case 0x85:      /* NEL */
  1640.       case 0x2028:    /* LINE SEPARATOR */
  1641.       case 0x2029:    /* PARAGRAPH SEPARATOR */
  1642.       break;
  1643.       }
  1644.     ecode++;
  1645.     break;
  1646.  
  1647. #ifdef SUPPORT_UCP
  1648.     /* Check the next character by Unicode property. We will get here only
  1649.     if the support is in the binary; otherwise a compile-time error occurs. */
  1650.  
  1651.     case OP_PROP:
  1652.     case OP_NOTPROP:
  1653.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1654.     GETCHARINCTEST(c, eptr);
  1655.       {
  1656.       int chartype, script;
  1657.       int category = _pcre_ucp_findprop(c, &chartype, &script);
  1658.  
  1659.       switch(ecode[1])
  1660.         {
  1661.         case PT_ANY:
  1662.         if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
  1663.         break;
  1664.  
  1665.         case PT_LAMP:
  1666.         if ((chartype == ucp_Lu ||
  1667.              chartype == ucp_Ll ||
  1668.              chartype == ucp_Lt) == (op == OP_NOTPROP))
  1669.           RRETURN(MATCH_NOMATCH);
  1670.          break;
  1671.  
  1672.         case PT_GC:
  1673.         if ((ecode[2] != category) == (op == OP_PROP))
  1674.           RRETURN(MATCH_NOMATCH);
  1675.         break;
  1676.  
  1677.         case PT_PC:
  1678.         if ((ecode[2] != chartype) == (op == OP_PROP))
  1679.           RRETURN(MATCH_NOMATCH);
  1680.         break;
  1681.  
  1682.         case PT_SC:
  1683.         if ((ecode[2] != script) == (op == OP_PROP))
  1684.           RRETURN(MATCH_NOMATCH);
  1685.         break;
  1686.  
  1687.         default:
  1688.         RRETURN(PCRE_ERROR_INTERNAL);
  1689.         }
  1690.  
  1691.       ecode += 3;
  1692.       }
  1693.     break;
  1694.  
  1695.     /* Match an extended Unicode sequence. We will get here only if the support
  1696.     is in the binary; otherwise a compile-time error occurs. */
  1697.  
  1698.     case OP_EXTUNI:
  1699.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1700.     GETCHARINCTEST(c, eptr);
  1701.       {
  1702.       int chartype, script;
  1703.       int category = _pcre_ucp_findprop(c, &chartype, &script);
  1704.       if (category == ucp_M) RRETURN(MATCH_NOMATCH);
  1705.       while (eptr < md->end_subject)
  1706.         {
  1707.         int len = 1;
  1708.         if (!utf8) c = *eptr; else
  1709.           {
  1710.           GETCHARLEN(c, eptr, len);
  1711.           }
  1712.         category = _pcre_ucp_findprop(c, &chartype, &script);
  1713.         if (category != ucp_M) break;
  1714.         eptr += len;
  1715.         }
  1716.       }
  1717.     ecode++;
  1718.     break;
  1719. #endif
  1720.  
  1721.  
  1722.     /* Match a back reference, possibly repeatedly. Look past the end of the
  1723.     item to see if there is repeat information following. The code is similar
  1724.     to that for character classes, but repeated for efficiency. Then obey
  1725.     similar code to character type repeats - written out again for speed.
  1726.     However, if the referenced string is the empty string, always treat
  1727.     it as matched, any number of times (otherwise there could be infinite
  1728.     loops). */
  1729.  
  1730.     case OP_REF:
  1731.       {
  1732.       offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
  1733.       ecode += 3;                                 /* Advance past item */
  1734.  
  1735.       /* If the reference is unset, set the length to be longer than the amount
  1736.       of subject left; this ensures that every attempt at a match fails. We
  1737.       can't just fail here, because of the possibility of quantifiers with zero
  1738.       minima. */
  1739.  
  1740.       length = (offset >= offset_top || md->offset_vector[offset] < 0)?
  1741.         md->end_subject - eptr + 1 :
  1742.         md->offset_vector[offset+1] - md->offset_vector[offset];
  1743.  
  1744.       /* Set up for repetition, or handle the non-repeated case */
  1745.  
  1746.       switch (*ecode)
  1747.         {
  1748.         case OP_CRSTAR:
  1749.         case OP_CRMINSTAR:
  1750.         case OP_CRPLUS:
  1751.         case OP_CRMINPLUS:
  1752.         case OP_CRQUERY:
  1753.         case OP_CRMINQUERY:
  1754.         c = *ecode++ - OP_CRSTAR;
  1755.         minimize = (c & 1) != 0;
  1756.         min = rep_min[c];                 /* Pick up values from tables; */
  1757.         max = rep_max[c];                 /* zero for max => infinity */
  1758.         if (max == 0) max = INT_MAX;
  1759.         break;
  1760.  
  1761.         case OP_CRRANGE:
  1762.         case OP_CRMINRANGE:
  1763.         minimize = (*ecode == OP_CRMINRANGE);
  1764.         min = GET2(ecode, 1);
  1765.         max = GET2(ecode, 3);
  1766.         if (max == 0) max = INT_MAX;
  1767.         ecode += 5;
  1768.         break;
  1769.  
  1770.         default:               /* No repeat follows */
  1771.         if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);
  1772.         eptr += length;
  1773.         continue;              /* With the main loop */
  1774.         }
  1775.  
  1776.       /* If the length of the reference is zero, just continue with the
  1777.       main loop. */
  1778.  
  1779.       if (length == 0) continue;
  1780.  
  1781.       /* First, ensure the minimum number of matches are present. We get back
  1782.       the length of the reference string explicitly rather than passing the
  1783.       address of eptr, so that eptr can be a register variable. */
  1784.  
  1785.       for (i = 1; i <= min; i++)
  1786.         {
  1787.         if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);
  1788.         eptr += length;
  1789.         }
  1790.  
  1791.       /* If min = max, continue at the same level without recursion.
  1792.       They are not both allowed to be zero. */
  1793.  
  1794.       if (min == max) continue;
  1795.  
  1796.       /* If minimizing, keep trying and advancing the pointer */
  1797.  
  1798.       if (minimize)
  1799.         {
  1800.         for (fi = min;; fi++)
  1801.           {
  1802.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
  1803.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1804.           if (fi >= max || !match_ref(offset, eptr, length, md, ims))
  1805.             RRETURN(MATCH_NOMATCH);
  1806.           eptr += length;
  1807.           }
  1808.         /* Control never gets here */
  1809.         }
  1810.  
  1811.       /* If maximizing, find the longest string and work backwards */
  1812.  
  1813.       else
  1814.         {
  1815.         pp = eptr;
  1816.         for (i = min; i < max; i++)
  1817.           {
  1818.           if (!match_ref(offset, eptr, length, md, ims)) break;
  1819.           eptr += length;
  1820.           }
  1821.         while (eptr >= pp)
  1822.           {
  1823.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
  1824.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1825.           eptr -= length;
  1826.           }
  1827.         RRETURN(MATCH_NOMATCH);
  1828.         }
  1829.       }
  1830.     /* Control never gets here */
  1831.  
  1832.  
  1833.  
  1834.     /* Match a bit-mapped character class, possibly repeatedly. This op code is
  1835.     used when all the characters in the class have values in the range 0-255,
  1836.     and either the matching is caseful, or the characters are in the range
  1837.     0-127 when UTF-8 processing is enabled. The only difference between
  1838.     OP_CLASS and OP_NCLASS occurs when a data character outside the range is
  1839.     encountered.
  1840.  
  1841.     First, look past the end of the item to see if there is repeat information
  1842.     following. Then obey similar code to character type repeats - written out
  1843.     again for speed. */
  1844.  
  1845.     case OP_NCLASS:
  1846.     case OP_CLASS:
  1847.       {
  1848.       data = ecode + 1;                /* Save for matching */
  1849.       ecode += 33;                     /* Advance past the item */
  1850.  
  1851.       switch (*ecode)
  1852.         {
  1853.         case OP_CRSTAR:
  1854.         case OP_CRMINSTAR:
  1855.         case OP_CRPLUS:
  1856.         case OP_CRMINPLUS:
  1857.         case OP_CRQUERY:
  1858.         case OP_CRMINQUERY:
  1859.         c = *ecode++ - OP_CRSTAR;
  1860.         minimize = (c & 1) != 0;
  1861.         min = rep_min[c];                 /* Pick up values from tables; */
  1862.         max = rep_max[c];                 /* zero for max => infinity */
  1863.         if (max == 0) max = INT_MAX;
  1864.         break;
  1865.  
  1866.         case OP_CRRANGE:
  1867.         case OP_CRMINRANGE:
  1868.         minimize = (*ecode == OP_CRMINRANGE);
  1869.         min = GET2(ecode, 1);
  1870.         max = GET2(ecode, 3);
  1871.         if (max == 0) max = INT_MAX;
  1872.         ecode += 5;
  1873.         break;
  1874.  
  1875.         default:               /* No repeat follows */
  1876.         min = max = 1;
  1877.         break;
  1878.         }
  1879.  
  1880.       /* First, ensure the minimum number of matches are present. */
  1881.  
  1882. #ifdef SUPPORT_UTF8
  1883.       /* UTF-8 mode */
  1884.       if (utf8)
  1885.         {
  1886.         for (i = 1; i <= min; i++)
  1887.           {
  1888.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1889.           GETCHARINC(c, eptr);
  1890.           if (c > 255)
  1891.             {
  1892.             if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
  1893.             }
  1894.           else
  1895.             {
  1896.             if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1897.             }
  1898.           }
  1899.         }
  1900.       else
  1901. #endif
  1902.       /* Not UTF-8 mode */
  1903.         {
  1904.         for (i = 1; i <= min; i++)
  1905.           {
  1906.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1907.           c = *eptr++;
  1908.           if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1909.           }
  1910.         }
  1911.  
  1912.       /* If max == min we can continue with the main loop without the
  1913.       need to recurse. */
  1914.  
  1915.       if (min == max) continue;
  1916.  
  1917.       /* If minimizing, keep testing the rest of the expression and advancing
  1918.       the pointer while it matches the class. */
  1919.  
  1920.       if (minimize)
  1921.         {
  1922. #ifdef SUPPORT_UTF8
  1923.         /* UTF-8 mode */
  1924.         if (utf8)
  1925.           {
  1926.           for (fi = min;; fi++)
  1927.             {
  1928.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
  1929.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1930.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1931.             GETCHARINC(c, eptr);
  1932.             if (c > 255)
  1933.               {
  1934.               if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
  1935.               }
  1936.             else
  1937.               {
  1938.               if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1939.               }
  1940.             }
  1941.           }
  1942.         else
  1943. #endif
  1944.         /* Not UTF-8 mode */
  1945.           {
  1946.           for (fi = min;; fi++)
  1947.             {
  1948.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
  1949.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1950.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1951.             c = *eptr++;
  1952.             if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1953.             }
  1954.           }
  1955.         /* Control never gets here */
  1956.         }
  1957.  
  1958.       /* If maximizing, find the longest possible run, then work backwards. */
  1959.  
  1960.       else
  1961.         {
  1962.         pp = eptr;
  1963.  
  1964. #ifdef SUPPORT_UTF8
  1965.         /* UTF-8 mode */
  1966.         if (utf8)
  1967.           {
  1968.           for (i = min; i < max; i++)
  1969.             {
  1970.             int len = 1;
  1971.             if (eptr >= md->end_subject) break;
  1972.             GETCHARLEN(c, eptr, len);
  1973.             if (c > 255)
  1974.               {
  1975.               if (op == OP_CLASS) break;
  1976.               }
  1977.             else
  1978.               {
  1979.               if ((data[c/8] & (1 << (c&7))) == 0) break;
  1980.               }
  1981.             eptr += len;
  1982.             }
  1983.           for (;;)
  1984.             {
  1985.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
  1986.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1987.             if (eptr-- == pp) break;        /* Stop if tried at original pos */
  1988.             BACKCHAR(eptr);
  1989.             }
  1990.           }
  1991.         else
  1992. #endif
  1993.           /* Not UTF-8 mode */
  1994.           {
  1995.           for (i = min; i < max; i++)
  1996.             {
  1997.             if (eptr >= md->end_subject) break;
  1998.             c = *eptr;
  1999.             if ((data[c/8] & (1 << (c&7))) == 0) break;
  2000.             eptr++;
  2001.             }
  2002.           while (eptr >= pp)
  2003.             {
  2004.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
  2005.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2006.             eptr--;
  2007.             }
  2008.           }
  2009.  
  2010.         RRETURN(MATCH_NOMATCH);
  2011.         }
  2012.       }
  2013.     /* Control never gets here */
  2014.  
  2015.  
  2016.     /* Match an extended character class. This opcode is encountered only
  2017.     in UTF-8 mode, because that's the only time it is compiled. */
  2018.  
  2019. #ifdef SUPPORT_UTF8
  2020.     case OP_XCLASS:
  2021.       {
  2022.       data = ecode + 1 + LINK_SIZE;                /* Save for matching */
  2023.       ecode += GET(ecode, 1);                      /* Advance past the item */
  2024.  
  2025.       switch (*ecode)
  2026.         {
  2027.         case OP_CRSTAR:
  2028.         case OP_CRMINSTAR:
  2029.         case OP_CRPLUS:
  2030.         case OP_CRMINPLUS:
  2031.         case OP_CRQUERY:
  2032.         case OP_CRMINQUERY:
  2033.         c = *ecode++ - OP_CRSTAR;
  2034.         minimize = (c & 1) != 0;
  2035.         min = rep_min[c];                 /* Pick up values from tables; */
  2036.         max = rep_max[c];                 /* zero for max => infinity */
  2037.         if (max == 0) max = INT_MAX;
  2038.         break;
  2039.  
  2040.         case OP_CRRANGE:
  2041.         case OP_CRMINRANGE:
  2042.         minimize = (*ecode == OP_CRMINRANGE);
  2043.         min = GET2(ecode, 1);
  2044.         max = GET2(ecode, 3);
  2045.         if (max == 0) max = INT_MAX;
  2046.         ecode += 5;
  2047.         break;
  2048.  
  2049.         default:               /* No repeat follows */
  2050.         min = max = 1;
  2051.         break;
  2052.         }
  2053.  
  2054.       /* First, ensure the minimum number of matches are present. */
  2055.  
  2056.       for (i = 1; i <= min; i++)
  2057.         {
  2058.         if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2059.         GETCHARINC(c, eptr);
  2060.         if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
  2061.         }
  2062.  
  2063.       /* If max == min we can continue with the main loop without the
  2064.       need to recurse. */
  2065.  
  2066.       if (min == max) continue;
  2067.  
  2068.       /* If minimizing, keep testing the rest of the expression and advancing
  2069.       the pointer while it matches the class. */
  2070.  
  2071.       if (minimize)
  2072.         {
  2073.         for (fi = min;; fi++)
  2074.           {
  2075.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
  2076.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2077.           if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2078.           GETCHARINC(c, eptr);
  2079.           if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
  2080.           }
  2081.         /* Control never gets here */
  2082.         }
  2083.  
  2084.       /* If maximizing, find the longest possible run, then work backwards. */
  2085.  
  2086.       else
  2087.         {
  2088.         pp = eptr;
  2089.         for (i = min; i < max; i++)
  2090.           {
  2091.           int len = 1;
  2092.           if (eptr >= md->end_subject) break;
  2093.           GETCHARLEN(c, eptr, len);
  2094.           if (!_pcre_xclass(c, data)) break;
  2095.           eptr += len;
  2096.           }
  2097.         for(;;)
  2098.           {
  2099.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
  2100.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2101.           if (eptr-- == pp) break;        /* Stop if tried at original pos */
  2102.           if (utf8) BACKCHAR(eptr);
  2103.           }
  2104.         RRETURN(MATCH_NOMATCH);
  2105.         }
  2106.  
  2107.       /* Control never gets here */
  2108.       }
  2109. #endif    /* End of XCLASS */
  2110.  
  2111.     /* Match a single character, casefully */
  2112.  
  2113.     case OP_CHAR:
  2114. #ifdef SUPPORT_UTF8
  2115.     if (utf8)
  2116.       {
  2117.       length = 1;
  2118.       ecode++;
  2119.       GETCHARLEN(fc, ecode, length);
  2120.       if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2121.       while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
  2122.       }
  2123.     else
  2124. #endif
  2125.  
  2126.     /* Non-UTF-8 mode */
  2127.       {
  2128.       if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);
  2129.       if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
  2130.       ecode += 2;
  2131.       }
  2132.     break;
  2133.  
  2134.     /* Match a single character, caselessly */
  2135.  
  2136.     case OP_CHARNC:
  2137. #ifdef SUPPORT_UTF8
  2138.     if (utf8)
  2139.       {
  2140.       length = 1;
  2141.       ecode++;
  2142.       GETCHARLEN(fc, ecode, length);
  2143.  
  2144.       if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2145.  
  2146.       /* If the pattern character's value is < 128, we have only one byte, and
  2147.       can use the fast lookup table. */
  2148.  
  2149.       if (fc < 128)
  2150.         {
  2151.         if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  2152.         }
  2153.  
  2154.       /* Otherwise we must pick up the subject character */
  2155.  
  2156.       else
  2157.         {
  2158.         unsigned int dc;
  2159.         GETCHARINC(dc, eptr);
  2160.         ecode += length;
  2161.  
  2162.         /* If we have Unicode property support, we can use it to test the other
  2163.         case of the character, if there is one. */
  2164.  
  2165.         if (fc != dc)
  2166.           {
  2167. #ifdef SUPPORT_UCP
  2168.           if (dc != _pcre_ucp_othercase(fc))
  2169. #endif
  2170.             RRETURN(MATCH_NOMATCH);
  2171.           }
  2172.         }
  2173.       }
  2174.     else
  2175. #endif   /* SUPPORT_UTF8 */
  2176.  
  2177.     /* Non-UTF-8 mode */
  2178.       {
  2179.       if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);
  2180.       if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  2181.       ecode += 2;
  2182.       }
  2183.     break;
  2184.  
  2185.     /* Match a single character repeatedly. */
  2186.  
  2187.     case OP_EXACT:
  2188.     min = max = GET2(ecode, 1);
  2189.     ecode += 3;
  2190.     goto REPEATCHAR;
  2191.  
  2192.     case OP_POSUPTO:
  2193.     possessive = TRUE;
  2194.     /* Fall through */
  2195.  
  2196.     case OP_UPTO:
  2197.     case OP_MINUPTO:
  2198.     min = 0;
  2199.     max = GET2(ecode, 1);
  2200.     minimize = *ecode == OP_MINUPTO;
  2201.     ecode += 3;
  2202.     goto REPEATCHAR;
  2203.  
  2204.     case OP_POSSTAR:
  2205.     possessive = TRUE;
  2206.     min = 0;
  2207.     max = INT_MAX;
  2208.     ecode++;
  2209.     goto REPEATCHAR;
  2210.  
  2211.     case OP_POSPLUS:
  2212.     possessive = TRUE;
  2213.     min = 1;
  2214.     max = INT_MAX;
  2215.     ecode++;
  2216.     goto REPEATCHAR;
  2217.  
  2218.     case OP_POSQUERY:
  2219.     possessive = TRUE;
  2220.     min = 0;
  2221.     max = 1;
  2222.     ecode++;
  2223.     goto REPEATCHAR;
  2224.  
  2225.     case OP_STAR:
  2226.     case OP_MINSTAR:
  2227.     case OP_PLUS:
  2228.     case OP_MINPLUS:
  2229.     case OP_QUERY:
  2230.     case OP_MINQUERY:
  2231.     c = *ecode++ - OP_STAR;
  2232.     minimize = (c & 1) != 0;
  2233.     min = rep_min[c];                 /* Pick up values from tables; */
  2234.     max = rep_max[c];                 /* zero for max => infinity */
  2235.     if (max == 0) max = INT_MAX;
  2236.  
  2237.     /* Common code for all repeated single-character matches. We can give
  2238.     up quickly if there are fewer than the minimum number of characters left in
  2239.     the subject. */
  2240.  
  2241.     REPEATCHAR:
  2242. #ifdef SUPPORT_UTF8
  2243.     if (utf8)
  2244.       {
  2245.       length = 1;
  2246.       charptr = ecode;
  2247.       GETCHARLEN(fc, ecode, length);
  2248.       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2249.       ecode += length;
  2250.  
  2251.       /* Handle multibyte character matching specially here. There is
  2252.       support for caseless matching if UCP support is present. */
  2253.  
  2254.       if (length > 1)
  2255.         {
  2256. #ifdef SUPPORT_UCP
  2257.         unsigned int othercase;
  2258.         if ((ims & PCRE_CASELESS) != 0 &&
  2259.             (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)
  2260.           oclength = _pcre_ord2utf8(othercase, occhars);
  2261.         else oclength = 0;
  2262. #endif  /* SUPPORT_UCP */
  2263.  
  2264.         for (i = 1; i <= min; i++)
  2265.           {
  2266.           if (memcmp(eptr, charptr, length) == 0) eptr += length;
  2267. #ifdef SUPPORT_UCP
  2268.           /* Need braces because of following else */
  2269.           else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
  2270.           else
  2271.             {
  2272.             if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
  2273.             eptr += oclength;
  2274.             }
  2275. #else   /* without SUPPORT_UCP */
  2276.           else { RRETURN(MATCH_NOMATCH); }
  2277. #endif  /* SUPPORT_UCP */
  2278.           }
  2279.  
  2280.         if (min == max) continue;
  2281.  
  2282.         if (minimize)
  2283.           {
  2284.           for (fi = min;; fi++)
  2285.             {
  2286.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
  2287.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2288.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2289.             if (memcmp(eptr, charptr, length) == 0) eptr += length;
  2290. #ifdef SUPPORT_UCP
  2291.             /* Need braces because of following else */
  2292.             else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
  2293.             else
  2294.               {
  2295.               if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
  2296.               eptr += oclength;
  2297.               }
  2298. #else   /* without SUPPORT_UCP */
  2299.             else { RRETURN (MATCH_NOMATCH); }
  2300. #endif  /* SUPPORT_UCP */
  2301.             }
  2302.           /* Control never gets here */
  2303.           }
  2304.  
  2305.         else  /* Maximize */
  2306.           {
  2307.           pp = eptr;
  2308.           for (i = min; i < max; i++)
  2309.             {
  2310.             if (eptr > md->end_subject - length) break;
  2311.             if (memcmp(eptr, charptr, length) == 0) eptr += length;
  2312. #ifdef SUPPORT_UCP
  2313.             else if (oclength == 0) break;
  2314.             else
  2315.               {
  2316.               if (memcmp(eptr, occhars, oclength) != 0) break;
  2317.               eptr += oclength;
  2318.               }
  2319. #else   /* without SUPPORT_UCP */
  2320.             else break;
  2321. #endif  /* SUPPORT_UCP */
  2322.             }
  2323.  
  2324.           if (possessive) continue;
  2325.           for(;;)
  2326.            {
  2327.            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
  2328.            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2329.            if (eptr == pp) RRETURN(MATCH_NOMATCH);
  2330. #ifdef SUPPORT_UCP
  2331.            eptr--;
  2332.            BACKCHAR(eptr);
  2333. #else   /* without SUPPORT_UCP */
  2334.            eptr -= length;
  2335. #endif  /* SUPPORT_UCP */
  2336.            }
  2337.           }
  2338.         /* Control never gets here */
  2339.         }
  2340.  
  2341.       /* If the length of a UTF-8 character is 1, we fall through here, and
  2342.       obey the code as for non-UTF-8 characters below, though in this case the
  2343.       value of fc will always be < 128. */
  2344.       }
  2345.     else
  2346. #endif  /* SUPPORT_UTF8 */
  2347.  
  2348.     /* When not in UTF-8 mode, load a single-byte character. */
  2349.       {
  2350.       if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2351.       fc = *ecode++;
  2352.       }
  2353.  
  2354.     /* The value of fc at this point is always less than 256, though we may or
  2355.     may not be in UTF-8 mode. The code is duplicated for the caseless and
  2356.     caseful cases, for speed, since matching characters is likely to be quite
  2357.     common. First, ensure the minimum number of matches are present. If min =
  2358.     max, continue at the same level without recursing. Otherwise, if
  2359.     minimizing, keep trying the rest of the expression and advancing one
  2360.     matching character if failing, up to the maximum. Alternatively, if
  2361.     maximizing, find the maximum number of characters and work backwards. */
  2362.  
  2363.     DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
  2364.       max, eptr));
  2365.  
  2366.     if ((ims & PCRE_CASELESS) != 0)
  2367.       {
  2368.       fc = md->lcc[fc];
  2369.       for (i = 1; i <= min; i++)
  2370.         if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  2371.       if (min == max) continue;
  2372.       if (minimize)
  2373.         {
  2374.         for (fi = min;; fi++)
  2375.           {
  2376.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
  2377.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2378.           if (fi >= max || eptr >= md->end_subject ||
  2379.               fc != md->lcc[*eptr++])
  2380.             RRETURN(MATCH_NOMATCH);
  2381.           }
  2382.         /* Control never gets here */
  2383.         }
  2384.       else  /* Maximize */
  2385.         {
  2386.         pp = eptr;
  2387.         for (i = min; i < max; i++)
  2388.           {
  2389.           if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
  2390.           eptr++;
  2391.           }
  2392.         if (possessive) continue;
  2393.         while (eptr >= pp)
  2394.           {
  2395.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
  2396.           eptr--;
  2397.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2398.           }
  2399.         RRETURN(MATCH_NOMATCH);
  2400.         }
  2401.       /* Control never gets here */
  2402.       }
  2403.  
  2404.     /* Caseful comparisons (includes all multi-byte characters) */
  2405.  
  2406.     else
  2407.       {
  2408.       for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
  2409.       if (min == max) continue;
  2410.       if (minimize)
  2411.         {
  2412.         for (fi = min;; fi++)
  2413.           {
  2414.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
  2415.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2416.           if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
  2417.             RRETURN(MATCH_NOMATCH);
  2418.           }
  2419.         /* Control never gets here */
  2420.         }
  2421.       else  /* Maximize */
  2422.         {
  2423.         pp = eptr;
  2424.         for (i = min; i < max; i++)
  2425.           {
  2426.           if (eptr >= md->end_subject || fc != *eptr) break;
  2427.           eptr++;
  2428.           }
  2429.         if (possessive) continue;
  2430.         while (eptr >= pp)
  2431.           {
  2432.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
  2433.           eptr--;
  2434.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2435.           }
  2436.         RRETURN(MATCH_NOMATCH);
  2437.         }
  2438.       }
  2439.     /* Control never gets here */
  2440.  
  2441.     /* Match a negated single one-byte character. The character we are
  2442.     checking can be multibyte. */
  2443.  
  2444.     case OP_NOT:
  2445.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2446.     ecode++;
  2447.     GETCHARINCTEST(c, eptr);
  2448.     if ((ims & PCRE_CASELESS) != 0)
  2449.       {
  2450. #ifdef SUPPORT_UTF8
  2451.       if (c < 256)
  2452. #endif
  2453.       c = md->lcc[c];
  2454.       if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);
  2455.       }
  2456.     else
  2457.       {
  2458.       if (*ecode++ == c) RRETURN(MATCH_NOMATCH);
  2459.       }
  2460.     break;
  2461.  
  2462.     /* Match a negated single one-byte character repeatedly. This is almost a
  2463.     repeat of the code for a repeated single character, but I haven't found a
  2464.     nice way of commoning these up that doesn't require a test of the
  2465.     positive/negative option for each character match. Maybe that wouldn't add
  2466.     very much to the time taken, but character matching *is* what this is all
  2467.     about... */
  2468.  
  2469.     case OP_NOTEXACT:
  2470.     min = max = GET2(ecode, 1);
  2471.     ecode += 3;
  2472.     goto REPEATNOTCHAR;
  2473.  
  2474.     case OP_NOTUPTO:
  2475.     case OP_NOTMINUPTO:
  2476.     min = 0;
  2477.     max = GET2(ecode, 1);
  2478.     minimize = *ecode == OP_NOTMINUPTO;
  2479.     ecode += 3;
  2480.     goto REPEATNOTCHAR;
  2481.  
  2482.     case OP_NOTPOSSTAR:
  2483.     possessive = TRUE;
  2484.     min = 0;
  2485.     max = INT_MAX;
  2486.     ecode++;
  2487.     goto REPEATNOTCHAR;
  2488.  
  2489.     case OP_NOTPOSPLUS:
  2490.     possessive = TRUE;
  2491.     min = 1;
  2492.     max = INT_MAX;
  2493.     ecode++;
  2494.     goto REPEATNOTCHAR;
  2495.  
  2496.     case OP_NOTPOSQUERY:
  2497.     possessive = TRUE;
  2498.     min = 0;
  2499.     max = 1;
  2500.     ecode++;
  2501.     goto REPEATNOTCHAR;
  2502.  
  2503.     case OP_NOTPOSUPTO:
  2504.     possessive = TRUE;
  2505.     min = 0;
  2506.     max = GET2(ecode, 1);
  2507.     ecode += 3;
  2508.     goto REPEATNOTCHAR;
  2509.  
  2510.     case OP_NOTSTAR:
  2511.     case OP_NOTMINSTAR:
  2512.     case OP_NOTPLUS:
  2513.     case OP_NOTMINPLUS:
  2514.     case OP_NOTQUERY:
  2515.     case OP_NOTMINQUERY:
  2516.     c = *ecode++ - OP_NOTSTAR;
  2517.     minimize = (c & 1) != 0;
  2518.     min = rep_min[c];                 /* Pick up values from tables; */
  2519.     max = rep_max[c];                 /* zero for max => infinity */
  2520.     if (max == 0) max = INT_MAX;
  2521.  
  2522.     /* Common code for all repeated single-byte matches. We can give up quickly
  2523.     if there are fewer than the minimum number of bytes left in the
  2524.     subject. */
  2525.  
  2526.     REPEATNOTCHAR:
  2527.     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2528.     fc = *ecode++;
  2529.  
  2530.     /* The code is duplicated for the caseless and caseful cases, for speed,
  2531.     since matching characters is likely to be quite common. First, ensure the
  2532.     minimum number of matches are present. If min = max, continue at the same
  2533.     level without recursing. Otherwise, if minimizing, keep trying the rest of
  2534.     the expression and advancing one matching character if failing, up to the
  2535.     maximum. Alternatively, if maximizing, find the maximum number of
  2536.     characters and work backwards. */
  2537.  
  2538.     DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max,
  2539.       max, eptr));
  2540.  
  2541.     if ((ims & PCRE_CASELESS) != 0)
  2542.       {
  2543.       fc = md->lcc[fc];
  2544.  
  2545. #ifdef SUPPORT_UTF8
  2546.       /* UTF-8 mode */
  2547.       if (utf8)
  2548.         {
  2549.         register unsigned int d;
  2550.         for (i = 1; i <= min; i++)
  2551.           {
  2552.           GETCHARINC(d, eptr);
  2553.           if (d < 256) d = md->lcc[d];
  2554.           if (fc == d) RRETURN(MATCH_NOMATCH);
  2555.           }
  2556.         }
  2557.       else
  2558. #endif
  2559.  
  2560.       /* Not UTF-8 mode */
  2561.         {
  2562.         for (i = 1; i <= min; i++)
  2563.           if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  2564.         }
  2565.  
  2566.       if (min == max) continue;
  2567.  
  2568.       if (minimize)
  2569.         {
  2570. #ifdef SUPPORT_UTF8
  2571.         /* UTF-8 mode */
  2572.         if (utf8)
  2573.           {
  2574.           register unsigned int d;
  2575.           for (fi = min;; fi++)
  2576.             {
  2577.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
  2578.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2579.             GETCHARINC(d, eptr);
  2580.             if (d < 256) d = md->lcc[d];
  2581.             if (fi >= max || eptr >= md->end_subject || fc == d)
  2582.               RRETURN(MATCH_NOMATCH);
  2583.             }
  2584.           }
  2585.         else
  2586. #endif
  2587.         /* Not UTF-8 mode */
  2588.           {
  2589.           for (fi = min;; fi++)
  2590.             {
  2591.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
  2592.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2593.             if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
  2594.               RRETURN(MATCH_NOMATCH);
  2595.             }
  2596.           }
  2597.         /* Control never gets here */
  2598.         }
  2599.  
  2600.       /* Maximize case */
  2601.  
  2602.       else
  2603.         {
  2604.         pp = eptr;
  2605.  
  2606. #ifdef SUPPORT_UTF8
  2607.         /* UTF-8 mode */
  2608.         if (utf8)
  2609.           {
  2610.           register unsigned int d;
  2611.           for (i = min; i < max; i++)
  2612.             {
  2613.             int len = 1;
  2614.             if (eptr >= md->end_subject) break;
  2615.             GETCHARLEN(d, eptr, len);
  2616.             if (d < 256) d = md->lcc[d];
  2617.             if (fc == d) break;
  2618.             eptr += len;
  2619.             }
  2620.         if (possessive) continue;
  2621.         for(;;)
  2622.             {
  2623.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
  2624.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2625.             if (eptr-- == pp) break;        /* Stop if tried at original pos */
  2626.             BACKCHAR(eptr);
  2627.             }
  2628.           }
  2629.         else
  2630. #endif
  2631.         /* Not UTF-8 mode */
  2632.           {
  2633.           for (i = min; i < max; i++)
  2634.             {
  2635.             if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
  2636.             eptr++;
  2637.             }
  2638.           if (possessive) continue;
  2639.           while (eptr >= pp)
  2640.             {
  2641.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
  2642.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2643.             eptr--;
  2644.             }
  2645.           }
  2646.  
  2647.         RRETURN(MATCH_NOMATCH);
  2648.         }
  2649.       /* Control never gets here */
  2650.       }
  2651.  
  2652.     /* Caseful comparisons */
  2653.  
  2654.     else
  2655.       {
  2656. #ifdef SUPPORT_UTF8
  2657.       /* UTF-8 mode */
  2658.       if (utf8)
  2659.         {
  2660.         register unsigned int d;
  2661.         for (i = 1; i <= min; i++)
  2662.           {
  2663.           GETCHARINC(d, eptr);
  2664.           if (fc == d) RRETURN(MATCH_NOMATCH);
  2665.           }
  2666.         }
  2667.       else
  2668. #endif
  2669.       /* Not UTF-8 mode */
  2670.         {
  2671.         for (i = 1; i <= min; i++)
  2672.           if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
  2673.         }
  2674.  
  2675.       if (min == max) continue;
  2676.  
  2677.       if (minimize)
  2678.         {
  2679. #ifdef SUPPORT_UTF8
  2680.         /* UTF-8 mode */
  2681.         if (utf8)
  2682.           {
  2683.           register unsigned int d;
  2684.           for (fi = min;; fi++)
  2685.             {
  2686.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
  2687.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2688.             GETCHARINC(d, eptr);
  2689.             if (fi >= max || eptr >= md->end_subject || fc == d)
  2690.               RRETURN(MATCH_NOMATCH);
  2691.             }
  2692.           }
  2693.         else
  2694. #endif
  2695.         /* Not UTF-8 mode */
  2696.           {
  2697.           for (fi = min;; fi++)
  2698.             {
  2699.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
  2700.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2701.             if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
  2702.               RRETURN(MATCH_NOMATCH);
  2703.             }
  2704.           }
  2705.         /* Control never gets here */
  2706.         }
  2707.  
  2708.       /* Maximize case */
  2709.  
  2710.       else
  2711.         {
  2712.         pp = eptr;
  2713.  
  2714. #ifdef SUPPORT_UTF8
  2715.         /* UTF-8 mode */
  2716.         if (utf8)
  2717.           {
  2718.           register unsigned int d;
  2719.           for (i = min; i < max; i++)
  2720.             {
  2721.             int len = 1;
  2722.             if (eptr >= md->end_subject) break;
  2723.             GETCHARLEN(d, eptr, len);
  2724.             if (fc == d) break;
  2725.             eptr += len;
  2726.             }
  2727.           if (possessive) continue;
  2728.           for(;;)
  2729.             {
  2730.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
  2731.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2732.             if (eptr-- == pp) break;        /* Stop if tried at original pos */
  2733.             BACKCHAR(eptr);
  2734.             }
  2735.           }
  2736.         else
  2737. #endif
  2738.         /* Not UTF-8 mode */
  2739.           {
  2740.           for (i = min; i < max; i++)
  2741.             {
  2742.             if (eptr >= md->end_subject || fc == *eptr) break;
  2743.             eptr++;
  2744.             }
  2745.           if (possessive) continue;
  2746.           while (eptr >= pp)
  2747.             {
  2748.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
  2749.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2750.             eptr--;
  2751.             }
  2752.           }
  2753.  
  2754.         RRETURN(MATCH_NOMATCH);
  2755.         }
  2756.       }
  2757.     /* Control never gets here */
  2758.  
  2759.     /* Match a single character type repeatedly; several different opcodes
  2760.     share code. This is very similar to the code for single characters, but we
  2761.     repeat it in the interests of efficiency. */
  2762.  
  2763.     case OP_TYPEEXACT:
  2764.     min = max = GET2(ecode, 1);
  2765.     minimize = TRUE;
  2766.     ecode += 3;
  2767.     goto REPEATTYPE;
  2768.  
  2769.     case OP_TYPEUPTO:
  2770.     case OP_TYPEMINUPTO:
  2771.     min = 0;
  2772.     max = GET2(ecode, 1);
  2773.     minimize = *ecode == OP_TYPEMINUPTO;
  2774.     ecode += 3;
  2775.     goto REPEATTYPE;
  2776.  
  2777.     case OP_TYPEPOSSTAR:
  2778.     possessive = TRUE;
  2779.     min = 0;
  2780.     max = INT_MAX;
  2781.     ecode++;
  2782.     goto REPEATTYPE;
  2783.  
  2784.     case OP_TYPEPOSPLUS:
  2785.     possessive = TRUE;
  2786.     min = 1;
  2787.     max = INT_MAX;
  2788.     ecode++;
  2789.     goto REPEATTYPE;
  2790.  
  2791.     case OP_TYPEPOSQUERY:
  2792.     possessive = TRUE;
  2793.     min = 0;
  2794.     max = 1;
  2795.     ecode++;
  2796.     goto REPEATTYPE;
  2797.  
  2798.     case OP_TYPEPOSUPTO:
  2799.     possessive = TRUE;
  2800.     min = 0;
  2801.     max = GET2(ecode, 1);
  2802.     ecode += 3;
  2803.     goto REPEATTYPE;
  2804.  
  2805.     case OP_TYPESTAR:
  2806.     case OP_TYPEMINSTAR:
  2807.     case OP_TYPEPLUS:
  2808.     case OP_TYPEMINPLUS:
  2809.     case OP_TYPEQUERY:
  2810.     case OP_TYPEMINQUERY:
  2811.     c = *ecode++ - OP_TYPESTAR;
  2812.     minimize = (c & 1) != 0;
  2813.     min = rep_min[c];                 /* Pick up values from tables; */
  2814.     max = rep_max[c];                 /* zero for max => infinity */
  2815.     if (max == 0) max = INT_MAX;
  2816.  
  2817.     /* Common code for all repeated single character type matches. Note that
  2818.     in UTF-8 mode, '.' matches a character of any length, but for the other
  2819.     character types, the valid characters are all one-byte long. */
  2820.  
  2821.     REPEATTYPE:
  2822.     ctype = *ecode++;      /* Code for the character type */
  2823.  
  2824. #ifdef SUPPORT_UCP
  2825.     if (ctype == OP_PROP || ctype == OP_NOTPROP)
  2826.       {
  2827.       prop_fail_result = ctype == OP_NOTPROP;
  2828.       prop_type = *ecode++;
  2829.       prop_value = *ecode++;
  2830.       }
  2831.     else prop_type = -1;
  2832. #endif
  2833.  
  2834.     /* First, ensure the minimum number of matches are present. Use inline
  2835.     code for maximizing the speed, and do the type test once at the start
  2836.     (i.e. keep it out of the loop). Also we can test that there are at least
  2837.     the minimum number of bytes before we start. This isn't as effective in
  2838.     UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that
  2839.     is tidier. Also separate the UCP code, which can be the same for both UTF-8
  2840.     and single-bytes. */
  2841.  
  2842.     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2843.     if (min > 0)
  2844.       {
  2845. #ifdef SUPPORT_UCP
  2846.       if (prop_type >= 0)
  2847.         {
  2848.         switch(prop_type)
  2849.           {
  2850.           case PT_ANY:
  2851.           if (prop_fail_result) RRETURN(MATCH_NOMATCH);
  2852.           for (i = 1; i <= min; i++)
  2853.             {
  2854.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2855.             GETCHARINCTEST(c, eptr);
  2856.             }
  2857.           break;
  2858.  
  2859.           case PT_LAMP:
  2860.           for (i = 1; i <= min; i++)
  2861.             {
  2862.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2863.             GETCHARINCTEST(c, eptr);
  2864.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2865.             if ((prop_chartype == ucp_Lu ||
  2866.                  prop_chartype == ucp_Ll ||
  2867.                  prop_chartype == ucp_Lt) == prop_fail_result)
  2868.               RRETURN(MATCH_NOMATCH);
  2869.             }
  2870.           break;
  2871.  
  2872.           case PT_GC:
  2873.           for (i = 1; i <= min; i++)
  2874.             {
  2875.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2876.             GETCHARINCTEST(c, eptr);
  2877.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2878.             if ((prop_category == prop_value) == prop_fail_result)
  2879.               RRETURN(MATCH_NOMATCH);
  2880.             }
  2881.           break;
  2882.  
  2883.           case PT_PC:
  2884.           for (i = 1; i <= min; i++)
  2885.             {
  2886.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2887.             GETCHARINCTEST(c, eptr);
  2888.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2889.             if ((prop_chartype == prop_value) == prop_fail_result)
  2890.               RRETURN(MATCH_NOMATCH);
  2891.             }
  2892.           break;
  2893.  
  2894.           case PT_SC:
  2895.           for (i = 1; i <= min; i++)
  2896.             {
  2897.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2898.             GETCHARINCTEST(c, eptr);
  2899.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2900.             if ((prop_script == prop_value) == prop_fail_result)
  2901.               RRETURN(MATCH_NOMATCH);
  2902.             }
  2903.           break;
  2904.  
  2905.           default:
  2906.           RRETURN(PCRE_ERROR_INTERNAL);
  2907.           }
  2908.         }
  2909.  
  2910.       /* Match extended Unicode sequences. We will get here only if the
  2911.       support is in the binary; otherwise a compile-time error occurs. */
  2912.  
  2913.       else if (ctype == OP_EXTUNI)
  2914.         {
  2915.         for (i = 1; i <= min; i++)
  2916.           {
  2917.           GETCHARINCTEST(c, eptr);
  2918.           prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2919.           if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
  2920.           while (eptr < md->end_subject)
  2921.             {
  2922.             int len = 1;
  2923.             if (!utf8) c = *eptr; else
  2924.               {
  2925.               GETCHARLEN(c, eptr, len);
  2926.               }
  2927.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2928.             if (prop_category != ucp_M) break;
  2929.             eptr += len;
  2930.             }
  2931.           }
  2932.         }
  2933.  
  2934.       else
  2935. #endif     /* SUPPORT_UCP */
  2936.  
  2937. /* Handle all other cases when the coding is UTF-8 */
  2938.  
  2939. #ifdef SUPPORT_UTF8
  2940.       if (utf8) switch(ctype)
  2941.         {
  2942.         case OP_ANY:
  2943.         for (i = 1; i <= min; i++)
  2944.           {
  2945.           if (eptr >= md->end_subject ||
  2946.                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
  2947.             RRETURN(MATCH_NOMATCH);
  2948.           eptr++;
  2949.           while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  2950.           }
  2951.         break;
  2952.  
  2953.         case OP_ANYBYTE:
  2954.         eptr += min;
  2955.         break;
  2956.  
  2957.         case OP_ANYNL:
  2958.         for (i = 1; i <= min; i++)
  2959.           {
  2960.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2961.           GETCHARINC(c, eptr);
  2962.           switch(c)
  2963.             {
  2964.             default: RRETURN(MATCH_NOMATCH);
  2965.             case 0x000d:
  2966.             if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  2967.             break;
  2968.  
  2969.             case 0x000a:
  2970.             break;
  2971.  
  2972.             case 0x000b:
  2973.             case 0x000c:
  2974.             case 0x0085:
  2975.             case 0x2028:
  2976.             case 0x2029:
  2977.             if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  2978.             break;
  2979.             }
  2980.           }
  2981.         break;
  2982.  
  2983.         case OP_NOT_HSPACE:
  2984.         for (i = 1; i <= min; i++)
  2985.           {
  2986.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2987.           GETCHARINC(c, eptr);
  2988.           switch(c)
  2989.             {
  2990.             default: break;
  2991.             case 0x09:      /* HT */
  2992.             case 0x20:      /* SPACE */
  2993.             case 0xa0:      /* NBSP */
  2994.             case 0x1680:    /* OGHAM SPACE MARK */
  2995.             case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
  2996.             case 0x2000:    /* EN QUAD */
  2997.             case 0x2001:    /* EM QUAD */
  2998.             case 0x2002:    /* EN SPACE */
  2999.             case 0x2003:    /* EM SPACE */
  3000.             case 0x2004:    /* THREE-PER-EM SPACE */
  3001.             case 0x2005:    /* FOUR-PER-EM SPACE */
  3002.             case 0x2006:    /* SIX-PER-EM SPACE */
  3003.             case 0x2007:    /* FIGURE SPACE */
  3004.             case 0x2008:    /* PUNCTUATION SPACE */
  3005.             case 0x2009:    /* THIN SPACE */
  3006.             case 0x200A:    /* HAIR SPACE */
  3007.             case 0x202f:    /* NARROW NO-BREAK SPACE */
  3008.             case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
  3009.             case 0x3000:    /* IDEOGRAPHIC SPACE */
  3010.             RRETURN(MATCH_NOMATCH);
  3011.             }
  3012.           }
  3013.         break;
  3014.  
  3015.         case OP_HSPACE:
  3016.         for (i = 1; i <= min; i++)
  3017.           {
  3018.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3019.           GETCHARINC(c, eptr);
  3020.           switch(c)
  3021.             {
  3022.             default: RRETURN(MATCH_NOMATCH);
  3023.             case 0x09:      /* HT */
  3024.             case 0x20:      /* SPACE */
  3025.             case 0xa0:      /* NBSP */
  3026.             case 0x1680:    /* OGHAM SPACE MARK */
  3027.             case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
  3028.             case 0x2000:    /* EN QUAD */
  3029.             case 0x2001:    /* EM QUAD */
  3030.             case 0x2002:    /* EN SPACE */
  3031.             case 0x2003:    /* EM SPACE */
  3032.             case 0x2004:    /* THREE-PER-EM SPACE */
  3033.             case 0x2005:    /* FOUR-PER-EM SPACE */
  3034.             case 0x2006:    /* SIX-PER-EM SPACE */
  3035.             case 0x2007:    /* FIGURE SPACE */
  3036.             case 0x2008:    /* PUNCTUATION SPACE */
  3037.             case 0x2009:    /* THIN SPACE */
  3038.             case 0x200A:    /* HAIR SPACE */
  3039.             case 0x202f:    /* NARROW NO-BREAK SPACE */
  3040.             case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
  3041.             case 0x3000:    /* IDEOGRAPHIC SPACE */
  3042.             break;
  3043.             }
  3044.           }
  3045.         break;
  3046.  
  3047.         case OP_NOT_VSPACE:
  3048.         for (i = 1; i <= min; i++)
  3049.           {
  3050.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3051.           GETCHARINC(c, eptr);
  3052.           switch(c)
  3053.             {
  3054.             default: break;
  3055.             case 0x0a:      /* LF */
  3056.             case 0x0b:      /* VT */
  3057.             case 0x0c:      /* FF */
  3058.             case 0x0d:      /* CR */
  3059.             case 0x85:      /* NEL */
  3060.             case 0x2028:    /* LINE SEPARATOR */
  3061.             case 0x2029:    /* PARAGRAPH SEPARATOR */
  3062.             RRETURN(MATCH_NOMATCH);
  3063.             }
  3064.           }
  3065.         break;
  3066.  
  3067.         case OP_VSPACE:
  3068.         for (i = 1; i <= min; i++)
  3069.           {
  3070.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3071.           GETCHARINC(c, eptr);
  3072.           switch(c)
  3073.             {
  3074.             default: RRETURN(MATCH_NOMATCH);
  3075.             case 0x0a:      /* LF */
  3076.             case 0x0b:      /* VT */
  3077.             case 0x0c:      /* FF */
  3078.             case 0x0d:      /* CR */
  3079.             case 0x85:      /* NEL */
  3080.             case 0x2028:    /* LINE SEPARATOR */
  3081.             case 0x2029:    /* PARAGRAPH SEPARATOR */
  3082.             break;
  3083.             }
  3084.           }
  3085.         break;
  3086.  
  3087.         case OP_NOT_DIGIT:
  3088.         for (i = 1; i <= min; i++)
  3089.           {
  3090.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3091.           GETCHARINC(c, eptr);
  3092.           if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
  3093.             RRETURN(MATCH_NOMATCH);
  3094.           }
  3095.         break;
  3096.  
  3097.         case OP_DIGIT:
  3098.         for (i = 1; i <= min; i++)
  3099.           {
  3100.           if (eptr >= md->end_subject ||
  3101.              *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
  3102.             RRETURN(MATCH_NOMATCH);
  3103.           /* No need to skip more bytes - we know it's a 1-byte character */
  3104.           }
  3105.         break;
  3106.  
  3107.         case OP_NOT_WHITESPACE:
  3108.         for (i = 1; i <= min; i++)
  3109.           {
  3110.           if (eptr >= md->end_subject ||
  3111.              (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
  3112.             RRETURN(MATCH_NOMATCH);
  3113.           while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
  3114.           }
  3115.         break;
  3116.  
  3117.         case OP_WHITESPACE:
  3118.         for (i = 1; i <= min; i++)
  3119.           {
  3120.           if (eptr >= md->end_subject ||
  3121.              *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
  3122.             RRETURN(MATCH_NOMATCH);
  3123.           /* No need to skip more bytes - we know it's a 1-byte character */
  3124.           }
  3125.         break;
  3126.  
  3127.         case OP_NOT_WORDCHAR:
  3128.         for (i = 1; i <= min; i++)
  3129.           {
  3130.           if (eptr >= md->end_subject ||
  3131.              (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
  3132.             RRETURN(MATCH_NOMATCH);
  3133.           while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
  3134.           }
  3135.         break;
  3136.  
  3137.         case OP_WORDCHAR:
  3138.         for (i = 1; i <= min; i++)
  3139.           {
  3140.           if (eptr >= md->end_subject ||
  3141.              *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
  3142.             RRETURN(MATCH_NOMATCH);
  3143.           /* No need to skip more bytes - we know it's a 1-byte character */
  3144.           }
  3145.         break;
  3146.  
  3147.         default:
  3148.         RRETURN(PCRE_ERROR_INTERNAL);
  3149.         }  /* End switch(ctype) */
  3150.  
  3151.       else
  3152. #endif     /* SUPPORT_UTF8 */
  3153.  
  3154.       /* Code for the non-UTF-8 case for minimum matching of operators other
  3155.       than OP_PROP and OP_NOTPROP. We can assume that there are the minimum
  3156.       number of bytes present, as this was tested above. */
  3157.  
  3158.       switch(ctype)
  3159.         {
  3160.         case OP_ANY:
  3161.         if ((ims & PCRE_DOTALL) == 0)
  3162.           {
  3163.           for (i = 1; i <= min; i++)
  3164.             {
  3165.             if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
  3166.             eptr++;
  3167.             }
  3168.           }
  3169.         else eptr += min;
  3170.         break;
  3171.  
  3172.         case OP_ANYBYTE:
  3173.         eptr += min;
  3174.         break;
  3175.  
  3176.         /* Because of the CRLF case, we can't assume the minimum number of
  3177.         bytes are present in this case. */
  3178.  
  3179.         case OP_ANYNL:
  3180.         for (i = 1; i <= min; i++)
  3181.           {
  3182.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3183.           switch(*eptr++)
  3184.             {
  3185.             default: RRETURN(MATCH_NOMATCH);
  3186.             case 0x000d:
  3187.             if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  3188.             break;
  3189.             case 0x000a:
  3190.             break;
  3191.  
  3192.             case 0x000b:
  3193.             case 0x000c:
  3194.             case 0x0085:
  3195.             if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  3196.             break;
  3197.             }
  3198.           }
  3199.         break;
  3200.  
  3201.         case OP_NOT_HSPACE:
  3202.         for (i = 1; i <= min; i++)
  3203.           {
  3204.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3205.           switch(*eptr++)
  3206.             {
  3207.             default: break;
  3208.             case 0x09:      /* HT */
  3209.             case 0x20:      /* SPACE */
  3210.             case 0xa0:      /* NBSP */
  3211.             RRETURN(MATCH_NOMATCH);
  3212.             }
  3213.           }
  3214.         break;
  3215.  
  3216.         case OP_HSPACE:
  3217.         for (i = 1; i <= min; i++)
  3218.           {
  3219.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3220.           switch(*eptr++)
  3221.             {
  3222.             default: RRETURN(MATCH_NOMATCH);
  3223.             case 0x09:      /* HT */
  3224.             case 0x20:      /* SPACE */
  3225.             case 0xa0:      /* NBSP */
  3226.             break;
  3227.             }
  3228.           }
  3229.         break;
  3230.  
  3231.         case OP_NOT_VSPACE:
  3232.         for (i = 1; i <= min; i++)
  3233.           {
  3234.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3235.           switch(*eptr++)
  3236.             {
  3237.             default: break;
  3238.             case 0x0a:      /* LF */
  3239.             case 0x0b:      /* VT */
  3240.             case 0x0c:      /* FF */
  3241.             case 0x0d:      /* CR */
  3242.             case 0x85:      /* NEL */
  3243.             RRETURN(MATCH_NOMATCH);
  3244.             }
  3245.           }
  3246.         break;
  3247.  
  3248.         case OP_VSPACE:
  3249.         for (i = 1; i <= min; i++)
  3250.           {
  3251.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3252.           switch(*eptr++)
  3253.             {
  3254.             default: RRETURN(MATCH_NOMATCH);
  3255.             case 0x0a:      /* LF */
  3256.             case 0x0b:      /* VT */
  3257.             case 0x0c:      /* FF */
  3258.             case 0x0d:      /* CR */
  3259.             case 0x85:      /* NEL */
  3260.             break;
  3261.             }
  3262.           }
  3263.         break;
  3264.  
  3265.         case OP_NOT_DIGIT:
  3266.         for (i = 1; i <= min; i++)
  3267.           if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
  3268.         break;
  3269.  
  3270.         case OP_DIGIT:
  3271.         for (i = 1; i <= min; i++)
  3272.           if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
  3273.         break;
  3274.  
  3275.         case OP_NOT_WHITESPACE:
  3276.         for (i = 1; i <= min; i++)
  3277.           if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
  3278.         break;
  3279.  
  3280.         case OP_WHITESPACE:
  3281.         for (i = 1; i <= min; i++)
  3282.           if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
  3283.         break;
  3284.  
  3285.         case OP_NOT_WORDCHAR:
  3286.         for (i = 1; i <= min; i++)
  3287.           if ((md->ctypes[*eptr++] & ctype_word) != 0)
  3288.             RRETURN(MATCH_NOMATCH);
  3289.         break;
  3290.  
  3291.         case OP_WORDCHAR:
  3292.         for (i = 1; i <= min; i++)
  3293.           if ((md->ctypes[*eptr++] & ctype_word) == 0)
  3294.             RRETURN(MATCH_NOMATCH);
  3295.         break;
  3296.  
  3297.         default:
  3298.         RRETURN(PCRE_ERROR_INTERNAL);
  3299.         }
  3300.       }
  3301.  
  3302.     /* If min = max, continue at the same level without recursing */
  3303.  
  3304.     if (min == max) continue;
  3305.  
  3306.     /* If minimizing, we have to test the rest of the pattern before each
  3307.     subsequent match. Again, separate the UTF-8 case for speed, and also
  3308.     separate the UCP cases. */
  3309.  
  3310.     if (minimize)
  3311.       {
  3312. #ifdef SUPPORT_UCP
  3313.       if (prop_type >= 0)
  3314.         {
  3315.         switch(prop_type)
  3316.           {
  3317.           case PT_ANY:
  3318.           for (fi = min;; fi++)
  3319.             {
  3320.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
  3321.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3322.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3323.             GETCHARINC(c, eptr);
  3324.             if (prop_fail_result) RRETURN(MATCH_NOMATCH);
  3325.             }
  3326.           /* Control never gets here */
  3327.  
  3328.           case PT_LAMP:
  3329.           for (fi = min;; fi++)
  3330.             {
  3331.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
  3332.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3333.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3334.             GETCHARINC(c, eptr);
  3335.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3336.             if ((prop_chartype == ucp_Lu ||
  3337.                  prop_chartype == ucp_Ll ||
  3338.                  prop_chartype == ucp_Lt) == prop_fail_result)
  3339.               RRETURN(MATCH_NOMATCH);
  3340.             }
  3341.           /* Control never gets here */
  3342.  
  3343.           case PT_GC:
  3344.           for (fi = min;; fi++)
  3345.             {
  3346.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
  3347.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3348.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3349.             GETCHARINC(c, eptr);
  3350.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3351.             if ((prop_category == prop_value) == prop_fail_result)
  3352.               RRETURN(MATCH_NOMATCH);
  3353.             }
  3354.           /* Control never gets here */
  3355.  
  3356.           case PT_PC:
  3357.           for (fi = min;; fi++)
  3358.             {
  3359.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
  3360.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3361.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3362.             GETCHARINC(c, eptr);
  3363.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3364.             if ((prop_chartype == prop_value) == prop_fail_result)
  3365.               RRETURN(MATCH_NOMATCH);
  3366.             }
  3367.           /* Control never gets here */
  3368.  
  3369.           case PT_SC:
  3370.           for (fi = min;; fi++)
  3371.             {
  3372.             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
  3373.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3374.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3375.             GETCHARINC(c, eptr);
  3376.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3377.             if ((prop_script == prop_value) == prop_fail_result)
  3378.               RRETURN(MATCH_NOMATCH);
  3379.             }
  3380.           /* Control never gets here */
  3381.  
  3382.           default:
  3383.           RRETURN(PCRE_ERROR_INTERNAL);
  3384.           }
  3385.         }
  3386.  
  3387.       /* Match extended Unicode sequences. We will get here only if the
  3388.       support is in the binary; otherwise a compile-time error occurs. */
  3389.  
  3390.       else if (ctype == OP_EXTUNI)
  3391.         {
  3392.         for (fi = min;; fi++)
  3393.           {
  3394.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
  3395.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3396.           if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3397.           GETCHARINCTEST(c, eptr);
  3398.           prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3399.           if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
  3400.           while (eptr < md->end_subject)
  3401.             {
  3402.             int len = 1;
  3403.             if (!utf8) c = *eptr; else
  3404.               {
  3405.               GETCHARLEN(c, eptr, len);
  3406.               }
  3407.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3408.             if (prop_category != ucp_M) break;
  3409.             eptr += len;
  3410.             }
  3411.           }
  3412.         }
  3413.  
  3414.       else
  3415. #endif     /* SUPPORT_UCP */
  3416.  
  3417. #ifdef SUPPORT_UTF8
  3418.       /* UTF-8 mode */
  3419.       if (utf8)
  3420.         {
  3421.         for (fi = min;; fi++)
  3422.           {
  3423.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
  3424.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3425.           if (fi >= max || eptr >= md->end_subject ||
  3426.                (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&
  3427.                 IS_NEWLINE(eptr)))
  3428.             RRETURN(MATCH_NOMATCH);
  3429.  
  3430.           GETCHARINC(c, eptr);
  3431.           switch(ctype)
  3432.             {
  3433.             case OP_ANY:        /* This is the DOTALL case */
  3434.             break;
  3435.  
  3436.             case OP_ANYBYTE:
  3437.             break;
  3438.  
  3439.             case OP_ANYNL:
  3440.             switch(c)
  3441.               {
  3442.               default: RRETURN(MATCH_NOMATCH);
  3443.               case 0x000d:
  3444.               if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  3445.               break;
  3446.               case 0x000a:
  3447.               break;
  3448.  
  3449.               case 0x000b:
  3450.               case 0x000c:
  3451.               case 0x0085:
  3452.               case 0x2028:
  3453.               case 0x2029:
  3454.               if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  3455.               break;
  3456.               }
  3457.             break;
  3458.  
  3459.             case OP_NOT_HSPACE:
  3460.             switch(c)
  3461.               {
  3462.               default: break;
  3463.               case 0x09:      /* HT */
  3464.               case 0x20:      /* SPACE */
  3465.               case 0xa0:      /* NBSP */
  3466.               case 0x1680:    /* OGHAM SPACE MARK */
  3467.               case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
  3468.               case 0x2000:    /* EN QUAD */
  3469.               case 0x2001:    /* EM QUAD */
  3470.               case 0x2002:    /* EN SPACE */
  3471.               case 0x2003:    /* EM SPACE */
  3472.               case 0x2004:    /* THREE-PER-EM SPACE */
  3473.               case 0x2005:    /* FOUR-PER-EM SPACE */
  3474.               case 0x2006:    /* SIX-PER-EM SPACE */
  3475.               case 0x2007:    /* FIGURE SPACE */
  3476.               case 0x2008:    /* PUNCTUATION SPACE */
  3477.               case 0x2009:    /* THIN SPACE */
  3478.               case 0x200A:    /* HAIR SPACE */
  3479.               case 0x202f:    /* NARROW NO-BREAK SPACE */
  3480.               case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
  3481.               case 0x3000:    /* IDEOGRAPHIC SPACE */
  3482.               RRETURN(MATCH_NOMATCH);
  3483.               }
  3484.             break;
  3485.  
  3486.             case OP_HSPACE:
  3487.             switch(c)
  3488.               {
  3489.               default: RRETURN(MATCH_NOMATCH);
  3490.               case 0x09:      /* HT */
  3491.               case 0x20:      /* SPACE */
  3492.               case 0xa0:      /* NBSP */
  3493.               case 0x1680:    /* OGHAM SPACE MARK */
  3494.               case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
  3495.               case 0x2000:    /* EN QUAD */
  3496.               case 0x2001:    /* EM QUAD */
  3497.               case 0x2002:    /* EN SPACE */
  3498.               case 0x2003:    /* EM SPACE */
  3499.               case 0x2004:    /* THREE-PER-EM SPACE */
  3500.               case 0x2005:    /* FOUR-PER-EM SPACE */
  3501.               case 0x2006:    /* SIX-PER-EM SPACE */
  3502.               case 0x2007:    /* FIGURE SPACE */
  3503.               case 0x2008:    /* PUNCTUATION SPACE */
  3504.               case 0x2009:    /* THIN SPACE */
  3505.               case 0x200A:    /* HAIR SPACE */
  3506.               case 0x202f:    /* NARROW NO-BREAK SPACE */
  3507.               case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
  3508.               case 0x3000:    /* IDEOGRAPHIC SPACE */
  3509.               break;
  3510.               }
  3511.             break;
  3512.  
  3513.             case OP_NOT_VSPACE:
  3514.             switch(c)
  3515.               {
  3516.               default: break;
  3517.               case 0x0a:      /* LF */
  3518.               case 0x0b:      /* VT */
  3519.               case 0x0c:      /* FF */
  3520.               case 0x0d:      /* CR */
  3521.               case 0x85:      /* NEL */
  3522.               case 0x2028:    /* LINE SEPARATOR */
  3523.               case 0x2029:    /* PARAGRAPH SEPARATOR */
  3524.               RRETURN(MATCH_NOMATCH);
  3525.               }
  3526.             break;
  3527.  
  3528.             case OP_VSPACE:
  3529.             switch(c)
  3530.               {
  3531.               default: RRETURN(MATCH_NOMATCH);
  3532.               case 0x0a:      /* LF */
  3533.               case 0x0b:      /* VT */
  3534.               case 0x0c:      /* FF */
  3535.               case 0x0d:      /* CR */
  3536.               case 0x85:      /* NEL */
  3537.               case 0x2028:    /* LINE SEPARATOR */
  3538.               case 0x2029:    /* PARAGRAPH SEPARATOR */
  3539.               break;
  3540.               }
  3541.             break;
  3542.  
  3543.             case OP_NOT_DIGIT:
  3544.             if (c < 256 && (md->ctypes[c] & ctype_digit) != 0)
  3545.               RRETURN(MATCH_NOMATCH);
  3546.             break;
  3547.  
  3548.             case OP_DIGIT:
  3549.             if (c >= 256 || (md->ctypes[c] & ctype_digit) == 0)
  3550.               RRETURN(MATCH_NOMATCH);
  3551.             break;
  3552.  
  3553.             case OP_NOT_WHITESPACE:
  3554.             if (c < 256 && (md->ctypes[c] & ctype_space) != 0)
  3555.               RRETURN(MATCH_NOMATCH);
  3556.             break;
  3557.  
  3558.             case OP_WHITESPACE:
  3559.             if  (c >= 256 || (md->ctypes[c] & ctype_space) == 0)
  3560.               RRETURN(MATCH_NOMATCH);
  3561.             break;
  3562.  
  3563.             case OP_NOT_WORDCHAR:
  3564.             if (c < 256 && (md->ctypes[c] & ctype_word) != 0)
  3565.               RRETURN(MATCH_NOMATCH);
  3566.             break;
  3567.  
  3568.             case OP_WORDCHAR:
  3569.             if (c >= 256 || (md->ctypes[c] & ctype_word) == 0)
  3570.               RRETURN(MATCH_NOMATCH);
  3571.             break;
  3572.  
  3573.             default:
  3574.             RRETURN(PCRE_ERROR_INTERNAL);
  3575.             }
  3576.           }
  3577.         }
  3578.       else
  3579. #endif
  3580.       /* Not UTF-8 mode */
  3581.         {
  3582.         for (fi = min;; fi++)
  3583.           {
  3584.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
  3585.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3586.           if (fi >= max || eptr >= md->end_subject ||
  3587.                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
  3588.             RRETURN(MATCH_NOMATCH);
  3589.  
  3590.           c = *eptr++;
  3591.           switch(ctype)
  3592.             {
  3593.             case OP_ANY:   /* This is the DOTALL case */
  3594.             break;
  3595.  
  3596.             case OP_ANYBYTE:
  3597.             break;
  3598.  
  3599.             case OP_ANYNL:
  3600.             switch(c)
  3601.               {
  3602.               default: RRETURN(MATCH_NOMATCH);
  3603.               case 0x000d:
  3604.               if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  3605.               break;
  3606.  
  3607.               case 0x000a:
  3608.               break;
  3609.  
  3610.               case 0x000b:
  3611.               case 0x000c:
  3612.               case 0x0085:
  3613.               if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  3614.               break;
  3615.               }
  3616.             break;
  3617.  
  3618.             case OP_NOT_HSPACE:
  3619.             switch(c)
  3620.               {
  3621.               default: break;
  3622.               case 0x09:      /* HT */
  3623.               case 0x20:      /* SPACE */
  3624.               case 0xa0:      /* NBSP */
  3625.               RRETURN(MATCH_NOMATCH);
  3626.               }
  3627.             break;
  3628.  
  3629.             case OP_HSPACE:
  3630.             switch(c)
  3631.               {
  3632.               default: RRETURN(MATCH_NOMATCH);
  3633.               case 0x09:      /* HT */
  3634.               case 0x20:      /* SPACE */
  3635.               case 0xa0:      /* NBSP */
  3636.               break;
  3637.               }
  3638.             break;
  3639.  
  3640.             case OP_NOT_VSPACE:
  3641.             switch(c)
  3642.               {
  3643.               default: break;
  3644.               case 0x0a:      /* LF */
  3645.               case 0x0b:      /* VT */
  3646.               case 0x0c:      /* FF */
  3647.               case 0x0d:      /* CR */
  3648.               case 0x85:      /* NEL */
  3649.               RRETURN(MATCH_NOMATCH);
  3650.               }
  3651.             break;
  3652.  
  3653.             case OP_VSPACE:
  3654.             switch(c)
  3655.               {
  3656.               default: RRETURN(MATCH_NOMATCH);
  3657.               case 0x0a:      /* LF */
  3658.               case 0x0b:      /* VT */
  3659.               case 0x0c:      /* FF */
  3660.               case 0x0d:      /* CR */
  3661.               case 0x85:      /* NEL */
  3662.               break;
  3663.               }
  3664.             break;
  3665.  
  3666.             case OP_NOT_DIGIT:
  3667.             if ((md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
  3668.             break;
  3669.  
  3670.             case OP_DIGIT:
  3671.             if ((md->ctypes[c] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
  3672.             break;
  3673.  
  3674.             case OP_NOT_WHITESPACE:
  3675.             if ((md->ctypes[c] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
  3676.             break;
  3677.  
  3678.             case OP_WHITESPACE:
  3679.             if  ((md->ctypes[c] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
  3680.             break;
  3681.  
  3682.             case OP_NOT_WORDCHAR:
  3683.             if ((md->ctypes[c] & ctype_word) != 0) RRETURN(MATCH_NOMATCH);
  3684.             break;
  3685.  
  3686.             case OP_WORDCHAR:
  3687.             if ((md->ctypes[c] & ctype_word) == 0) RRETURN(MATCH_NOMATCH);
  3688.             break;
  3689.  
  3690.             default:
  3691.             RRETURN(PCRE_ERROR_INTERNAL);
  3692.             }
  3693.           }
  3694.         }
  3695.       /* Control never gets here */
  3696.       }
  3697.  
  3698.     /* If maximizing, it is worth using inline code for speed, doing the type
  3699.     test once at the start (i.e. keep it out of the loop). Again, keep the
  3700.     UTF-8 and UCP stuff separate. */
  3701.  
  3702.     else
  3703.       {
  3704.       pp = eptr;  /* Remember where we started */
  3705.  
  3706. #ifdef SUPPORT_UCP
  3707.       if (prop_type >= 0)
  3708.         {
  3709.         switch(prop_type)
  3710.           {
  3711.           case PT_ANY:
  3712.           for (i = min; i < max; i++)
  3713.             {
  3714.             int len = 1;
  3715.             if (eptr >= md->end_subject) break;
  3716.             GETCHARLEN(c, eptr, len);
  3717.             if (prop_fail_result) break;
  3718.             eptr+= len;
  3719.             }
  3720.           break;
  3721.  
  3722.           case PT_LAMP:
  3723.           for (i = min; i < max; i++)
  3724.             {
  3725.             int len = 1;
  3726.             if (eptr >= md->end_subject) break;
  3727.             GETCHARLEN(c, eptr, len);
  3728.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3729.             if ((prop_chartype == ucp_Lu ||
  3730.                  prop_chartype == ucp_Ll ||
  3731.                  prop_chartype == ucp_Lt) == prop_fail_result)
  3732.               break;
  3733.             eptr+= len;
  3734.             }
  3735.           break;
  3736.  
  3737.           case PT_GC:
  3738.           for (i = min; i < max; i++)
  3739.             {
  3740.             int len = 1;
  3741.             if (eptr >= md->end_subject) break;
  3742.             GETCHARLEN(c, eptr, len);
  3743.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3744.             if ((prop_category == prop_value) == prop_fail_result)
  3745.               break;
  3746.             eptr+= len;
  3747.             }
  3748.           break;
  3749.  
  3750.           case PT_PC:
  3751.           for (i = min; i < max; i++)
  3752.             {
  3753.             int len = 1;
  3754.             if (eptr >= md->end_subject) break;
  3755.             GETCHARLEN(c, eptr, len);
  3756.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3757.             if ((prop_chartype == prop_value) == prop_fail_result)
  3758.               break;
  3759.             eptr+= len;
  3760.             }
  3761.           break;
  3762.  
  3763.           case PT_SC:
  3764.           for (i = min; i < max; i++)
  3765.             {
  3766.             int len = 1;
  3767.             if (eptr >= md->end_subject) break;
  3768.             GETCHARLEN(c, eptr, len);
  3769.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3770.             if ((prop_script == prop_value) == prop_fail_result)
  3771.               break;
  3772.             eptr+= len;
  3773.             }
  3774.           break;
  3775.           }
  3776.  
  3777.         /* eptr is now past the end of the maximum run */
  3778.  
  3779.         if (possessive) continue;
  3780.         for(;;)
  3781.           {
  3782.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
  3783.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3784.           if (eptr-- == pp) break;        /* Stop if tried at original pos */
  3785.           if (utf8) BACKCHAR(eptr);
  3786.           }
  3787.         }
  3788.  
  3789.       /* Match extended Unicode sequences. We will get here only if the
  3790.       support is in the binary; otherwise a compile-time error occurs. */
  3791.  
  3792.       else if (ctype == OP_EXTUNI)
  3793.         {
  3794.         for (i = min; i < max; i++)
  3795.           {
  3796.           if (eptr >= md->end_subject) break;
  3797.           GETCHARINCTEST(c, eptr);
  3798.           prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3799.           if (prop_category == ucp_M) break;
  3800.           while (eptr < md->end_subject)
  3801.             {
  3802.             int len = 1;
  3803.             if (!utf8) c = *eptr; else
  3804.               {
  3805.               GETCHARLEN(c, eptr, len);
  3806.               }
  3807.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3808.             if (prop_category != ucp_M) break;
  3809.             eptr += len;
  3810.             }
  3811.           }
  3812.  
  3813.         /* eptr is now past the end of the maximum run */
  3814.  
  3815.         if (possessive) continue;
  3816.         for(;;)
  3817.           {
  3818.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
  3819.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3820.           if (eptr-- == pp) break;        /* Stop if tried at original pos */
  3821.           for (;;)                        /* Move back over one extended */
  3822.             {
  3823.             int len = 1;
  3824.             if (!utf8) c = *eptr; else
  3825.               {
  3826.               BACKCHAR(eptr);
  3827.               GETCHARLEN(c, eptr, len);
  3828.               }
  3829.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3830.             if (prop_category != ucp_M) break;
  3831.             eptr--;
  3832.             }
  3833.           }
  3834.         }
  3835.  
  3836.       else
  3837. #endif   /* SUPPORT_UCP */
  3838.  
  3839. #ifdef SUPPORT_UTF8
  3840.       /* UTF-8 mode */
  3841.  
  3842.       if (utf8)
  3843.         {
  3844.         switch(ctype)
  3845.           {
  3846.           case OP_ANY:
  3847.           if (max < INT_MAX)
  3848.             {
  3849.             if ((ims & PCRE_DOTALL) == 0)
  3850.               {
  3851.               for (i = min; i < max; i++)
  3852.                 {
  3853.                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  3854.                 eptr++;
  3855.                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  3856.                 }
  3857.               }
  3858.             else
  3859.               {
  3860.               for (i = min; i < max; i++)
  3861.                 {
  3862.                 if (eptr >= md->end_subject) break;
  3863.                 eptr++;
  3864.                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  3865.                 }
  3866.               }
  3867.             }
  3868.  
  3869.           /* Handle unlimited UTF-8 repeat */
  3870.  
  3871.           else
  3872.             {
  3873.             if ((ims & PCRE_DOTALL) == 0)
  3874.               {
  3875.               for (i = min; i < max; i++)
  3876.                 {
  3877.                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  3878.                 eptr++;
  3879.                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  3880.                 }
  3881.               }
  3882.             else
  3883.               {
  3884.               eptr = md->end_subject;
  3885.               }
  3886.             }
  3887.           break;
  3888.  
  3889.           /* The byte case is the same as non-UTF8 */
  3890.  
  3891.           case OP_ANYBYTE:
  3892.           c = max - min;
  3893.           if (c > (unsigned int)(md->end_subject - eptr))
  3894.             c = md->end_subject - eptr;
  3895.           eptr += c;
  3896.           break;
  3897.  
  3898.           case OP_ANYNL:
  3899.           for (i = min; i < max; i++)
  3900.             {
  3901.             int len = 1;
  3902.             if (eptr >= md->end_subject) break;
  3903.             GETCHARLEN(c, eptr, len);
  3904.             if (c == 0x000d)
  3905.               {
  3906.               if (++eptr >= md->end_subject) break;
  3907.               if (*eptr == 0x000a) eptr++;
  3908.               }
  3909.             else
  3910.               {
  3911.               if (c != 0x000a &&
  3912.                   (md->bsr_anycrlf ||
  3913.                    (c != 0x000b && c != 0x000c &&
  3914.                     c != 0x0085 && c != 0x2028 && c != 0x2029)))
  3915.                 break;
  3916.               eptr += len;
  3917.               }
  3918.             }
  3919.           break;
  3920.  
  3921.           case OP_NOT_HSPACE:
  3922.           case OP_HSPACE:
  3923.           for (i = min; i < max; i++)
  3924.             {
  3925.             BOOL gotspace;
  3926.             int len = 1;
  3927.             if (eptr >= md->end_subject) break;
  3928.             GETCHARLEN(c, eptr, len);
  3929.             switch(c)
  3930.               {
  3931.               default: gotspace = FALSE; break;
  3932.               case 0x09:      /* HT */
  3933.               case 0x20:      /* SPACE */
  3934.               case 0xa0:      /* NBSP */
  3935.               case 0x1680:    /* OGHAM SPACE MARK */
  3936.               case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
  3937.               case 0x2000:    /* EN QUAD */
  3938.               case 0x2001:    /* EM QUAD */
  3939.               case 0x2002:    /* EN SPACE */
  3940.               case 0x2003:    /* EM SPACE */
  3941.               case 0x2004:    /* THREE-PER-EM SPACE */
  3942.               case 0x2005:    /* FOUR-PER-EM SPACE */
  3943.               case 0x2006:    /* SIX-PER-EM SPACE */
  3944.               case 0x2007:    /* FIGURE SPACE */
  3945.               case 0x2008:    /* PUNCTUATION SPACE */
  3946.               case 0x2009:    /* THIN SPACE */
  3947.               case 0x200A:    /* HAIR SPACE */
  3948.               case 0x202f:    /* NARROW NO-BREAK SPACE */
  3949.               case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
  3950.               case 0x3000:    /* IDEOGRAPHIC SPACE */
  3951.               gotspace = TRUE;
  3952.               break;
  3953.               }
  3954.             if (gotspace == (ctype == OP_NOT_HSPACE)) break;
  3955.             eptr += len;
  3956.             }
  3957.           break;
  3958.  
  3959.           case OP_NOT_VSPACE:
  3960.           case OP_VSPACE:
  3961.           for (i = min; i < max; i++)
  3962.             {
  3963.             BOOL gotspace;
  3964.             int len = 1;
  3965.             if (eptr >= md->end_subject) break;
  3966.             GETCHARLEN(c, eptr, len);
  3967.             switch(c)
  3968.               {
  3969.               default: gotspace = FALSE; break;
  3970.               case 0x0a:      /* LF */
  3971.               case 0x0b:      /* VT */
  3972.               case 0x0c:      /* FF */
  3973.               case 0x0d:      /* CR */
  3974.               case 0x85:      /* NEL */
  3975.               case 0x2028:    /* LINE SEPARATOR */
  3976.               case 0x2029:    /* PARAGRAPH SEPARATOR */
  3977.               gotspace = TRUE;
  3978.               break;
  3979.               }
  3980.             if (gotspace == (ctype == OP_NOT_VSPACE)) break;
  3981.             eptr += len;
  3982.             }
  3983.           break;
  3984.  
  3985.           case OP_NOT_DIGIT:
  3986.           for (i = min; i < max; i++)
  3987.             {
  3988.             int len = 1;
  3989.             if (eptr >= md->end_subject) break;
  3990.             GETCHARLEN(c, eptr, len);
  3991.             if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;
  3992.             eptr+= len;
  3993.             }
  3994.           break;
  3995.  
  3996.           case OP_DIGIT:
  3997.           for (i = min; i < max; i++)
  3998.             {
  3999.             int len = 1;
  4000.             if (eptr >= md->end_subject) break;
  4001.             GETCHARLEN(c, eptr, len);
  4002.             if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;
  4003.             eptr+= len;
  4004.             }
  4005.           break;
  4006.  
  4007.           case OP_NOT_WHITESPACE:
  4008.           for (i = min; i < max; i++)
  4009.             {
  4010.             int len = 1;
  4011.             if (eptr >= md->end_subject) break;
  4012.             GETCHARLEN(c, eptr, len);
  4013.             if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;
  4014.             eptr+= len;
  4015.             }
  4016.           break;
  4017.  
  4018.           case OP_WHITESPACE:
  4019.           for (i = min; i < max; i++)
  4020.             {
  4021.             int len = 1;
  4022.             if (eptr >= md->end_subject) break;
  4023.             GETCHARLEN(c, eptr, len);
  4024.             if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;
  4025.             eptr+= len;
  4026.             }
  4027.           break;
  4028.  
  4029.           case OP_NOT_WORDCHAR:
  4030.           for (i = min; i < max; i++)
  4031.             {
  4032.             int len = 1;
  4033.             if (eptr >= md->end_subject) break;
  4034.             GETCHARLEN(c, eptr, len);
  4035.             if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;
  4036.             eptr+= len;
  4037.             }
  4038.           break;
  4039.  
  4040.           case OP_WORDCHAR:
  4041.           for (i = min; i < max; i++)
  4042.             {
  4043.             int len = 1;
  4044.             if (eptr >= md->end_subject) break;
  4045.             GETCHARLEN(c, eptr, len);
  4046.             if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;
  4047.             eptr+= len;
  4048.             }
  4049.           break;
  4050.  
  4051.           default:
  4052.           RRETURN(PCRE_ERROR_INTERNAL);
  4053.           }
  4054.  
  4055.         /* eptr is now past the end of the maximum run */
  4056.  
  4057.         if (possessive) continue;
  4058.         for(;;)
  4059.           {
  4060.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
  4061.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  4062.           if (eptr-- == pp) break;        /* Stop if tried at original pos */
  4063.           BACKCHAR(eptr);
  4064.           }
  4065.         }
  4066.       else
  4067. #endif  /* SUPPORT_UTF8 */
  4068.  
  4069.       /* Not UTF-8 mode */
  4070.         {
  4071.         switch(ctype)
  4072.           {
  4073.           case OP_ANY:
  4074.           if ((ims & PCRE_DOTALL) == 0)
  4075.             {
  4076.             for (i = min; i < max; i++)
  4077.               {
  4078.               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  4079.               eptr++;
  4080.               }
  4081.             break;
  4082.             }
  4083.           /* For DOTALL case, fall through and treat as \C */
  4084.  
  4085.           case OP_ANYBYTE:
  4086.           c = max - min;
  4087.           if (c > (unsigned int)(md->end_subject - eptr))
  4088.             c = md->end_subject - eptr;
  4089.           eptr += c;
  4090.           break;
  4091.  
  4092.           case OP_ANYNL:
  4093.           for (i = min; i < max; i++)
  4094.             {
  4095.             if (eptr >= md->end_subject) break;
  4096.             c = *eptr;
  4097.             if (c == 0x000d)
  4098.               {
  4099.               if (++eptr >= md->end_subject) break;
  4100.               if (*eptr == 0x000a) eptr++;
  4101.               }
  4102.             else
  4103.               {
  4104.               if (c != 0x000a &&
  4105.                   (md->bsr_anycrlf ||
  4106.                     (c != 0x000b && c != 0x000c && c != 0x0085)))
  4107.                 break;
  4108.               eptr++;
  4109.               }
  4110.             }
  4111.           break;
  4112.  
  4113.           case OP_NOT_HSPACE:
  4114.           for (i = min; i < max; i++)
  4115.             {
  4116.             if (eptr >= md->end_subject) break;
  4117.             c = *eptr;
  4118.             if (c == 0x09 || c == 0x20 || c == 0xa0) break;
  4119.             eptr++;
  4120.             }
  4121.           break;
  4122.  
  4123.           case OP_HSPACE:
  4124.           for (i = min; i < max; i++)
  4125.             {
  4126.             if (eptr >= md->end_subject) break;
  4127.             c = *eptr;
  4128.             if (c != 0x09 && c != 0x20 && c != 0xa0) break;
  4129.             eptr++;
  4130.             }
  4131.           break;
  4132.  
  4133.           case OP_NOT_VSPACE:
  4134.           for (i = min; i < max; i++)
  4135.             {
  4136.             if (eptr >= md->end_subject) break;
  4137.             c = *eptr;
  4138.             if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
  4139.               break;
  4140.             eptr++;
  4141.             }
  4142.           break;
  4143.  
  4144.           case OP_VSPACE:
  4145.           for (i = min; i < max; i++)
  4146.             {
  4147.             if (eptr >= md->end_subject) break;
  4148.             c = *eptr;
  4149.             if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
  4150.               break;
  4151.             eptr++;
  4152.             }
  4153.           break;
  4154.  
  4155.           case OP_NOT_DIGIT:
  4156.           for (i = min; i < max; i++)
  4157.             {
  4158.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) != 0)
  4159.               break;
  4160.             eptr++;
  4161.             }
  4162.           break;
  4163.  
  4164.           case OP_DIGIT:
  4165.           for (i = min; i < max; i++)
  4166.             {
  4167.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) == 0)
  4168.               break;
  4169.             eptr++;
  4170.             }
  4171.           break;
  4172.  
  4173.           case OP_NOT_WHITESPACE:
  4174.           for (i = min; i < max; i++)
  4175.             {
  4176.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) != 0)
  4177.               break;
  4178.             eptr++;
  4179.             }
  4180.           break;
  4181.  
  4182.           case OP_WHITESPACE:
  4183.           for (i = min; i < max; i++)
  4184.             {
  4185.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) == 0)
  4186.               break;
  4187.             eptr++;
  4188.             }
  4189.           break;
  4190.  
  4191.           case OP_NOT_WORDCHAR:
  4192.           for (i = min; i < max; i++)
  4193.             {
  4194.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) != 0)
  4195.               break;
  4196.             eptr++;
  4197.             }
  4198.           break;
  4199.  
  4200.           case OP_WORDCHAR:
  4201.           for (i = min; i < max; i++)
  4202.             {
  4203.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) == 0)
  4204.               break;
  4205.             eptr++;
  4206.             }
  4207.           break;
  4208.  
  4209.           default:
  4210.           RRETURN(PCRE_ERROR_INTERNAL);
  4211.           }
  4212.  
  4213.         /* eptr is now past the end of the maximum run */
  4214.  
  4215.         if (possessive) continue;
  4216.         while (eptr >= pp)
  4217.           {
  4218.           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
  4219.           eptr--;
  4220.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  4221.           }
  4222.         }
  4223.  
  4224.       /* Get here if we can't make it match with any permitted repetitions */
  4225.  
  4226.       RRETURN(MATCH_NOMATCH);
  4227.       }
  4228.     /* Control never gets here */
  4229.  
  4230.     /* There's been some horrible disaster. Arrival here can only mean there is
  4231.     something seriously wrong in the code above or the OP_xxx definitions. */
  4232.  
  4233.     default:
  4234.     DPRINTF(("Unknown opcode %d\n", *ecode));
  4235.     RRETURN(PCRE_ERROR_UNKNOWN_OPCODE);
  4236.     }
  4237.  
  4238.   /* Do not stick any code in here without much thought; it is assumed
  4239.   that "continue" in the code above comes out to here to repeat the main
  4240.   loop. */
  4241.  
  4242.   }             /* End of main loop */
  4243. /* Control never reaches here */
  4244.  
  4245.  
  4246. /* When compiling to use the heap rather than the stack for recursive calls to
  4247. match(), the RRETURN() macro jumps here. The number that is saved in
  4248. frame->Xwhere indicates which label we actually want to return to. */
  4249.  
  4250. #ifdef NO_RECURSE
  4251. #define LBL(val) case val: goto L_RM##val;
  4252. HEAP_RETURN:
  4253. switch (frame->Xwhere)
  4254.   {
  4255.   LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
  4256.   LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
  4257.   LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
  4258.   LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
  4259.   LBL(53) LBL(54)
  4260. #ifdef SUPPORT_UTF8
  4261.   LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
  4262.   LBL(32) LBL(34) LBL(42) LBL(46)
  4263. #ifdef SUPPORT_UCP
  4264.   LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
  4265. #endif  /* SUPPORT_UCP */
  4266. #endif  /* SUPPORT_UTF8 */
  4267.   default:
  4268.   DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
  4269.   return PCRE_ERROR_INTERNAL;
  4270.   }
  4271. #undef LBL
  4272. #endif  /* NO_RECURSE */
  4273. }
  4274.  
  4275.  
  4276. /***************************************************************************
  4277. ****************************************************************************
  4278.                    RECURSION IN THE match() FUNCTION
  4279.  
  4280. Undefine all the macros that were defined above to handle this. */
  4281.  
  4282. #ifdef NO_RECURSE
  4283. #undef eptr
  4284. #undef ecode
  4285. #undef mstart
  4286. #undef offset_top
  4287. #undef ims
  4288. #undef eptrb
  4289. #undef flags
  4290.  
  4291. #undef callpat
  4292. #undef charptr
  4293. #undef data
  4294. #undef next
  4295. #undef pp
  4296. #undef prev
  4297. #undef saved_eptr
  4298.  
  4299. #undef new_recursive
  4300.  
  4301. #undef cur_is_word
  4302. #undef condition
  4303. #undef prev_is_word
  4304.  
  4305. #undef original_ims
  4306.  
  4307. #undef ctype
  4308. #undef length
  4309. #undef max
  4310. #undef min
  4311. #undef number
  4312. #undef offset
  4313. #undef op
  4314. #undef save_capture_last
  4315. #undef save_offset1
  4316. #undef save_offset2
  4317. #undef save_offset3
  4318. #undef stacksave
  4319.  
  4320. #undef newptrb
  4321.  
  4322. #endif
  4323.  
  4324. /* These two are defined as macros in both cases */
  4325.  
  4326. #undef fc
  4327. #undef fi
  4328.  
  4329. /***************************************************************************
  4330. ***************************************************************************/
  4331.  
  4332.  
  4333.  
  4334. /*************************************************
  4335. *         Execute a Regular Expression           *
  4336. *************************************************/
  4337.  
  4338. /* This function applies a compiled re to a subject string and picks out
  4339. portions of the string if it matches. Two elements in the vector are set for
  4340. each substring: the offsets to the start and end of the substring.
  4341.  
  4342. Arguments:
  4343.   argument_re     points to the compiled expression
  4344.   extra_data      points to extra data or is NULL
  4345.   subject         points to the subject string
  4346.   length          length of subject string (may contain binary zeros)
  4347.   start_offset    where to start in the subject string
  4348.   options         option bits
  4349.   offsets         points to a vector of ints to be filled in with offsets
  4350.   offsetcount     the number of elements in the vector
  4351.  
  4352. Returns:          > 0 => success; value is the number of elements filled in
  4353.                   = 0 => success, but offsets is not big enough
  4354.                    -1 => failed to match
  4355.                  < -1 => some kind of unexpected problem
  4356. */
  4357.  
  4358. PCRE_EXP_DEFN int
  4359. pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
  4360.   PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
  4361.   int offsetcount)
  4362. {
  4363. int rc, resetcount, ocount;
  4364. int first_byte = -1;
  4365. int req_byte = -1;
  4366. int req_byte2 = -1;
  4367. int newline;
  4368. unsigned long int ims;
  4369. BOOL using_temporary_offsets = FALSE;
  4370. BOOL anchored;
  4371. BOOL startline;
  4372. BOOL firstline;
  4373. BOOL first_byte_caseless = FALSE;
  4374. BOOL req_byte_caseless = FALSE;
  4375. #ifdef SUPPORT_UTF8 /* AutoHotkey: This helps detected unintended usages of utf8. */
  4376.     BOOL utf8;
  4377. #endif /* AutoHotkey. */
  4378. match_data match_block;
  4379. match_data *md = &match_block;
  4380. const uschar *tables;
  4381. const uschar *start_bits = NULL;
  4382. USPTR start_match = (USPTR)subject + start_offset;
  4383. USPTR end_subject;
  4384. USPTR req_byte_ptr = start_match - 1;
  4385.  
  4386. pcre_study_data internal_study;
  4387. const pcre_study_data *study;
  4388.  
  4389. real_pcre internal_re;
  4390. const real_pcre *external_re = (const real_pcre *)argument_re;
  4391. const real_pcre *re = external_re;
  4392.  
  4393. /* Plausibility checks */
  4394.  
  4395. if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
  4396. if (re == NULL || subject == NULL ||
  4397.    (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
  4398. if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
  4399.  
  4400. /* Fish out the optional data from the extra_data structure, first setting
  4401. the default values. */
  4402.  
  4403. study = NULL;
  4404. md->match_limit = MATCH_LIMIT;
  4405. md->match_limit_recursion = MATCH_LIMIT_RECURSION;
  4406. md->callout_data = NULL;
  4407.  
  4408. /* The table pointer is always in native byte order. */
  4409.  
  4410. tables = external_re->tables;
  4411.  
  4412. if (extra_data != NULL)
  4413.   {
  4414.   register unsigned int flags = extra_data->flags;
  4415.   if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)
  4416.     study = (const pcre_study_data *)extra_data->study_data;
  4417.   if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)
  4418.     md->match_limit = extra_data->match_limit;
  4419.   if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)
  4420.     md->match_limit_recursion = extra_data->match_limit_recursion;
  4421.   if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)
  4422.     md->callout_data = extra_data->callout_data;
  4423.   if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;
  4424.   }
  4425.  
  4426. /* If the exec call supplied NULL for tables, use the inbuilt ones. This
  4427. is a feature that makes it possible to save compiled regex and re-use them
  4428. in other programs later. */
  4429.  
  4430. if (tables == NULL) tables = _pcre_default_tables;
  4431.  
  4432. /* Check that the first field in the block is the magic number. If it is not,
  4433. test for a regex that was compiled on a host of opposite endianness. If this is
  4434. the case, flipped values are put in internal_re and internal_study if there was
  4435. study data too. */
  4436.  
  4437. if (re->magic_number != MAGIC_NUMBER)
  4438.   {
  4439.   re = _pcre_try_flipped(re, &internal_re, study, &internal_study);
  4440.   if (re == NULL) return PCRE_ERROR_BADMAGIC;
  4441.   if (study != NULL) study = &internal_study;
  4442.   }
  4443.  
  4444. /* Set up other data */
  4445.  
  4446. anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
  4447. startline = (re->flags & PCRE_STARTLINE) != 0;
  4448. firstline = (re->options & PCRE_FIRSTLINE) != 0;
  4449.  
  4450. /* The code starts after the real_pcre block and the capture name table. */
  4451.  
  4452. md->start_code = (const uschar *)external_re + re->name_table_offset +
  4453.   re->name_count * re->name_entry_size;
  4454.  
  4455. md->start_subject = (USPTR)subject;
  4456. md->start_offset = start_offset;
  4457. md->end_subject = md->start_subject + length;
  4458. end_subject = md->end_subject;
  4459.  
  4460. md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
  4461. #ifdef SUPPORT_UTF8 /* AutoHotkey. */
  4462.     utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
  4463. #endif /* AutoHotkey. */
  4464.  
  4465. md->notbol = (options & PCRE_NOTBOL) != 0;
  4466. md->noteol = (options & PCRE_NOTEOL) != 0;
  4467. md->notempty = (options & PCRE_NOTEMPTY) != 0;
  4468. md->partial = (options & PCRE_PARTIAL) != 0;
  4469. md->hitend = FALSE;
  4470.  
  4471. md->recursive = NULL;                   /* No recursion at top level */
  4472.  
  4473. md->lcc = tables + lcc_offset;
  4474. md->ctypes = tables + ctypes_offset;
  4475.  
  4476. /* Handle different \R options. */
  4477.  
  4478. switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
  4479.   {
  4480.   case 0:
  4481.   if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
  4482.     md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
  4483.   else
  4484. #ifdef BSR_ANYCRLF
  4485.   md->bsr_anycrlf = TRUE;
  4486. #else
  4487.   md->bsr_anycrlf = FALSE;
  4488. #endif
  4489.   break;
  4490.  
  4491.   case PCRE_BSR_ANYCRLF:
  4492.   md->bsr_anycrlf = TRUE;
  4493.   break;
  4494.  
  4495.   case PCRE_BSR_UNICODE:
  4496.   md->bsr_anycrlf = FALSE;
  4497.   break;
  4498.  
  4499.   default: return PCRE_ERROR_BADNEWLINE;
  4500.   }
  4501.  
  4502. /* Handle different types of newline. The three bits give eight cases. If
  4503. nothing is set at run time, whatever was used at compile time applies. */
  4504.  
  4505. switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
  4506.         (pcre_uint32)options) & PCRE_NEWLINE_BITS)
  4507.   {
  4508.   case 0: newline = NEWLINE; break;   /* Compile-time default */
  4509.   case PCRE_NEWLINE_CR: newline = '\r'; break;
  4510.   case PCRE_NEWLINE_LF: newline = '\n'; break;
  4511.   case PCRE_NEWLINE_CR+
  4512.        PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
  4513.   case PCRE_NEWLINE_ANY: newline = -1; break;
  4514.   case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
  4515.   default: return PCRE_ERROR_BADNEWLINE;
  4516.   }
  4517.  
  4518. if (newline == -2)
  4519.   {
  4520.   md->nltype = NLTYPE_ANYCRLF;
  4521.   }
  4522. else if (newline < 0)
  4523.   {
  4524.   md->nltype = NLTYPE_ANY;
  4525.   }
  4526. else
  4527.   {
  4528.   md->nltype = NLTYPE_FIXED;
  4529.   if (newline > 255)
  4530.     {
  4531.     md->nllen = 2;
  4532.     md->nl[0] = (newline >> 8) & 255;
  4533.     md->nl[1] = newline & 255;
  4534.     }
  4535.   else
  4536.     {
  4537.     md->nllen = 1;
  4538.     md->nl[0] = newline;
  4539.     }
  4540.   }
  4541.  
  4542. /* Partial matching is supported only for a restricted set of regexes at the
  4543. moment. */
  4544.  
  4545. if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
  4546.   return PCRE_ERROR_BADPARTIAL;
  4547.  
  4548. /* Check a UTF-8 string if required. Unfortunately there's no way of passing
  4549. back the character offset. */
  4550.  
  4551. #ifdef SUPPORT_UTF8
  4552. if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
  4553.   {
  4554.   if (_pcre_valid_utf8((uschar *)subject, length) >= 0)
  4555.     return PCRE_ERROR_BADUTF8;
  4556.   if (start_offset > 0 && start_offset < length)
  4557.     {
  4558.     int tb = ((uschar *)subject)[start_offset];
  4559.     if (tb > 127)
  4560.       {
  4561.       tb &= 0xc0;
  4562.       if (tb != 0 && tb != 0xc0) return PCRE_ERROR_BADUTF8_OFFSET;
  4563.       }
  4564.     }
  4565.   }
  4566. #endif
  4567.  
  4568. /* The ims options can vary during the matching as a result of the presence
  4569. of (?ims) items in the pattern. They are kept in a local variable so that
  4570. restoring at the exit of a group is easy. */
  4571.  
  4572. ims = re->options & (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL);
  4573.  
  4574. /* If the expression has got more back references than the offsets supplied can
  4575. hold, we get a temporary chunk of working store to use during the matching.
  4576. Otherwise, we can use the vector supplied, rounding down its size to a multiple
  4577. of 3. */
  4578.  
  4579. ocount = offsetcount - (offsetcount % 3);
  4580.  
  4581. if (re->top_backref > 0 && re->top_backref >= ocount/3)
  4582.   {
  4583.   ocount = re->top_backref * 3 + 3;
  4584.   md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));
  4585.   if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
  4586.   using_temporary_offsets = TRUE;
  4587.   DPRINTF(("Got memory to hold back references\n"));
  4588.   }
  4589. else md->offset_vector = offsets;
  4590.  
  4591. md->offset_end = ocount;
  4592. md->offset_max = (2*ocount)/3;
  4593. md->offset_overflow = FALSE;
  4594. md->capture_last = -1;
  4595.  
  4596. /* Compute the minimum number of offsets that we need to reset each time. Doing
  4597. this makes a huge difference to execution time when there aren't many brackets
  4598. in the pattern. */
  4599.  
  4600. resetcount = 2 + re->top_bracket * 2;
  4601. if (resetcount > offsetcount) resetcount = ocount;
  4602.  
  4603. /* Reset the working variable associated with each extraction. These should
  4604. never be used unless previously set, but they get saved and restored, and so we
  4605. initialize them to avoid reading uninitialized locations. */
  4606.  
  4607. if (md->offset_vector != NULL)
  4608.   {
  4609.   register int *iptr = md->offset_vector + ocount;
  4610.   register int *iend = iptr - resetcount/2 + 1;
  4611.   while (--iptr >= iend) *iptr = -1;
  4612.   }
  4613.  
  4614. /* Set up the first character to match, if available. The first_byte value is
  4615. never set for an anchored regular expression, but the anchoring may be forced
  4616. at run time, so we have to test for anchoring. The first char may be unset for
  4617. an unanchored pattern, of course. If there's no first char and the pattern was
  4618. studied, there may be a bitmap of possible first characters. */
  4619.  
  4620. if (!anchored)
  4621.   {
  4622.   if ((re->flags & PCRE_FIRSTSET) != 0)
  4623.     {
  4624.     first_byte = re->first_byte & 255;
  4625.     if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
  4626.       first_byte = md->lcc[first_byte];
  4627.     }
  4628.   else
  4629.     if (!startline && study != NULL &&
  4630.       (study->options & PCRE_STUDY_MAPPED) != 0)
  4631.         start_bits = study->start_bits;
  4632.   }
  4633.  
  4634. /* For anchored or unanchored matches, there may be a "last known required
  4635. character" set. */
  4636.  
  4637. if ((re->flags & PCRE_REQCHSET) != 0)
  4638.   {
  4639.   req_byte = re->req_byte & 255;
  4640.   req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
  4641.   req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */
  4642.   }
  4643.  
  4644.  
  4645. /* ==========================================================================*/
  4646.  
  4647. /* Loop for handling unanchored repeated matching attempts; for anchored regexs
  4648. the loop runs just once. */
  4649.  
  4650. for(;;)
  4651.   {
  4652.   USPTR save_end_subject = end_subject;
  4653.   USPTR new_start_match;
  4654.  
  4655.   /* Reset the maximum number of extractions we might see. */
  4656.  
  4657.   if (md->offset_vector != NULL)
  4658.     {
  4659.     register int *iptr = md->offset_vector;
  4660.     register int *iend = iptr + resetcount;
  4661.     while (iptr < iend) *iptr++ = -1;
  4662.     }
  4663.  
  4664.   /* Advance to a unique first char if possible. If firstline is TRUE, the
  4665.   start of the match is constrained to the first line of a multiline string.
  4666.   That is, the match must be before or at the first newline. Implement this by
  4667.   temporarily adjusting end_subject so that we stop scanning at a newline. If
  4668.   the match fails at the newline, later code breaks this loop. */
  4669.  
  4670.   if (firstline)
  4671.     {
  4672.     USPTR t = start_match;
  4673.     while (t < md->end_subject && !IS_NEWLINE(t)) t++;
  4674.     end_subject = t;
  4675.     }
  4676.  
  4677.   /* Now test for a unique first byte */
  4678.  
  4679.   if (first_byte >= 0)
  4680.     {
  4681.     if (first_byte_caseless)
  4682.       while (start_match < end_subject &&
  4683.              md->lcc[*start_match] != first_byte)
  4684.         start_match++;
  4685.     else
  4686.       while (start_match < end_subject && *start_match != first_byte)
  4687.         start_match++;
  4688.     }
  4689.  
  4690.   /* Or to just after a linebreak for a multiline match if possible */
  4691.  
  4692.   else if (startline)
  4693.     {
  4694.     if (start_match > md->start_subject + start_offset)
  4695.       {
  4696.       while (start_match <= end_subject && !WAS_NEWLINE(start_match))
  4697.         start_match++;
  4698.  
  4699.       /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
  4700.       and we are now at a LF, advance the match position by one more character.
  4701.       */
  4702.  
  4703.       if (start_match[-1] == '\r' &&
  4704.            (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
  4705.            start_match < end_subject &&
  4706.            *start_match == '\n')
  4707.         start_match++;
  4708.       }
  4709.     }
  4710.  
  4711.   /* Or to a non-unique first char after study */
  4712.  
  4713.   else if (start_bits != NULL)
  4714.     {
  4715.     while (start_match < end_subject)
  4716.       {
  4717.       register unsigned int c = *start_match;
  4718.       if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;
  4719.       }
  4720.     }
  4721.  
  4722.   /* Restore fudged end_subject */
  4723.  
  4724.   end_subject = save_end_subject;
  4725.  
  4726. #ifdef DEBUG  /* Sigh. Some compilers never learn. */
  4727.   printf(">>>> Match against: ");
  4728.   pchars(start_match, end_subject - start_match, TRUE, md);
  4729.   printf("\n");
  4730. #endif
  4731.  
  4732.   /* If req_byte is set, we know that that character must appear in the subject
  4733.   for the match to succeed. If the first character is set, req_byte must be
  4734.   later in the subject; otherwise the test starts at the match point. This
  4735.   optimization can save a huge amount of backtracking in patterns with nested
  4736.   unlimited repeats that aren't going to match. Writing separate code for
  4737.   cased/caseless versions makes it go faster, as does using an autoincrement
  4738.   and backing off on a match.
  4739.  
  4740.   HOWEVER: when the subject string is very, very long, searching to its end can
  4741.   take a long time, and give bad performance on quite ordinary patterns. This
  4742.   showed up when somebody was matching something like /^\d+C/ on a 32-megabyte
  4743.   string... so we don't do this when the string is sufficiently long.
  4744.  
  4745.   ALSO: this processing is disabled when partial matching is requested.
  4746.   */
  4747.  
  4748.   if (req_byte >= 0 &&
  4749.       end_subject - start_match < REQ_BYTE_MAX &&
  4750.       !md->partial)
  4751.     {
  4752.     register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
  4753.  
  4754.     /* We don't need to repeat the search if we haven't yet reached the
  4755.     place we found it at last time. */
  4756.  
  4757.     if (p > req_byte_ptr)
  4758.       {
  4759.       if (req_byte_caseless)
  4760.         {
  4761.         while (p < end_subject)
  4762.           {
  4763.           register int pp = *p++;
  4764.           if (pp == req_byte || pp == req_byte2) { p--; break; }
  4765.           }
  4766.         }
  4767.       else
  4768.         {
  4769.         while (p < end_subject)
  4770.           {
  4771.           if (*p++ == req_byte) { p--; break; }
  4772.           }
  4773.         }
  4774.  
  4775.       /* If we can't find the required character, break the matching loop,
  4776.       forcing a match failure. */
  4777.  
  4778.       if (p >= end_subject)
  4779.         {
  4780.         rc = MATCH_NOMATCH;
  4781.         break;
  4782.         }
  4783.  
  4784.       /* If we have found the required character, save the point where we
  4785.       found it, so that we don't search again next time round the loop if
  4786.       the start hasn't passed this character yet. */
  4787.  
  4788.       req_byte_ptr = p;
  4789.       }
  4790.     }
  4791.  
  4792.   /* OK, we can now run the match. */
  4793.  
  4794.   md->start_match_ptr = start_match;
  4795.   md->match_call_count = 0;
  4796.   rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);
  4797.  
  4798.   switch(rc)
  4799.     {
  4800.     /* NOMATCH and PRUNE advance by one character. THEN at this level acts
  4801.     exactly like PRUNE. */
  4802.  
  4803.     case MATCH_NOMATCH:
  4804.     case MATCH_PRUNE:
  4805.     case MATCH_THEN:
  4806.     new_start_match = start_match + 1;
  4807. #ifdef SUPPORT_UTF8
  4808.     if (utf8)
  4809.       while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)
  4810.         new_start_match++;
  4811. #endif
  4812.     break;
  4813.  
  4814.     /* SKIP passes back the next starting point explicitly. */
  4815.  
  4816.     case MATCH_SKIP:
  4817.     new_start_match = md->start_match_ptr;
  4818.     break;
  4819.  
  4820.     /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
  4821.  
  4822.     case MATCH_COMMIT:
  4823.     rc = MATCH_NOMATCH;
  4824.     goto ENDLOOP;
  4825.  
  4826.     /* Any other return is some kind of error. */
  4827.  
  4828.     default:
  4829.     goto ENDLOOP;
  4830.     }
  4831.  
  4832.   /* Control reaches here for the various types of "no match at this point"
  4833.   result. Reset the code to MATCH_NOMATCH for subsequent checking. */
  4834.  
  4835.   rc = MATCH_NOMATCH;
  4836.  
  4837.   /* If PCRE_FIRSTLINE is set, the match must happen before or at the first
  4838.   newline in the subject (though it may continue over the newline). Therefore,
  4839.   if we have just failed to match, starting at a newline, do not continue. */
  4840.  
  4841.   if (firstline && IS_NEWLINE(start_match)) break;
  4842.  
  4843.   /* Advance to new matching position */
  4844.  
  4845.   start_match = new_start_match;
  4846.  
  4847.   /* Break the loop if the pattern is anchored or if we have passed the end of
  4848.   the subject. */
  4849.  
  4850.   if (anchored || start_match > end_subject) break;
  4851.  
  4852.   /* If we have just passed a CR and we are now at a LF, and the pattern does
  4853.   not contain any explicit matches for \r or \n, and the newline option is CRLF
  4854.   or ANY or ANYCRLF, advance the match position by one more character. */
  4855.  
  4856.   if (start_match[-1] == '\r' &&
  4857.       start_match < end_subject &&
  4858.       *start_match == '\n' &&
  4859.       (re->flags & PCRE_HASCRORLF) == 0 &&
  4860.         (md->nltype == NLTYPE_ANY ||
  4861.          md->nltype == NLTYPE_ANYCRLF ||
  4862.          md->nllen == 2))
  4863.     start_match++;
  4864.  
  4865.   }   /* End of for(;;) "bumpalong" loop */
  4866.  
  4867. /* ==========================================================================*/
  4868.  
  4869. /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
  4870. conditions is true:
  4871.  
  4872. (1) The pattern is anchored or the match was failed by (*COMMIT);
  4873.  
  4874. (2) We are past the end of the subject;
  4875.  
  4876. (3) PCRE_FIRSTLINE is set and we have failed to match at a newline, because
  4877.     this option requests that a match occur at or before the first newline in
  4878.     the subject.
  4879.  
  4880. When we have a match and the offset vector is big enough to deal with any
  4881. backreferences, captured substring offsets will already be set up. In the case
  4882. where we had to get some local store to hold offsets for backreference
  4883. processing, copy those that we can. In this case there need not be overflow if
  4884. certain parts of the pattern were not used, even though there are more
  4885. capturing parentheses than vector slots. */
  4886.  
  4887. ENDLOOP:
  4888.  
  4889. if (rc == MATCH_MATCH)
  4890.   {
  4891.   if (using_temporary_offsets)
  4892.     {
  4893.     if (offsetcount >= 4)
  4894.       {
  4895.       memcpy(offsets + 2, md->offset_vector + 2,
  4896.         (offsetcount - 2) * sizeof(int));
  4897.       DPRINTF(("Copied offsets from temporary memory\n"));
  4898.       }
  4899.     if (md->end_offset_top > offsetcount) md->offset_overflow = TRUE;
  4900.     DPRINTF(("Freeing temporary memory\n"));
  4901.     (pcre_free)(md->offset_vector);
  4902.     }
  4903.  
  4904.   /* Set the return code to the number of captured strings, or 0 if there are
  4905.   too many to fit into the vector. */
  4906.  
  4907.   rc = md->offset_overflow? 0 : md->end_offset_top/2;
  4908.  
  4909.   /* If there is space, set up the whole thing as substring 0. The value of
  4910.   md->start_match_ptr might be modified if \K was encountered on the success
  4911.   matching path. */
  4912.  
  4913.   if (offsetcount < 2) rc = 0; else
  4914.     {
  4915.     offsets[0] = md->start_match_ptr - md->start_subject;
  4916.     offsets[1] = md->end_match_ptr - md->start_subject;
  4917.     }
  4918.  
  4919.   DPRINTF((">>>> returning %d\n", rc));
  4920.   return rc;
  4921.   }
  4922.  
  4923. /* Control gets here if there has been an error, or if the overall match
  4924. attempt has failed at all permitted starting positions. */
  4925.  
  4926. if (using_temporary_offsets)
  4927.   {
  4928.   DPRINTF(("Freeing temporary memory\n"));
  4929.   (pcre_free)(md->offset_vector);
  4930.   }
  4931.  
  4932. if (rc != MATCH_NOMATCH)
  4933.   {
  4934.   DPRINTF((">>>> error: returning %d\n", rc));
  4935.   return rc;
  4936.   }
  4937. else if (md->partial && md->hitend)
  4938.   {
  4939.   DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
  4940.   return PCRE_ERROR_PARTIAL;
  4941.   }
  4942. else
  4943.   {
  4944.   DPRINTF((">>>> returning PCRE_ERROR_NOMATCH\n"));
  4945.   return PCRE_ERROR_NOMATCH;
  4946.   }
  4947. }
  4948.  
  4949. /* End of pcre_exec.c */
  4950.